// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_TEST_BASE_BROWSER_WITH_TEST_WINDOW_TEST_H_ #define CHROME_TEST_BASE_BROWSER_WITH_TEST_WINDOW_TEST_H_ #include <memory> #include <vector> #include "base/compiler_specific.h" #include "base/memory/raw_ptr.h" #include "build/build_config.h" #include "build/chromeos_buildflags.h" #include "chrome/browser/performance_manager/test_support/test_user_performance_tuning_manager_environment.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_observer.h" #include "chrome/browser/ui/browser.h" #include "chrome/test/base/test_browser_window.h" #include "chrome/test/base/testing_profile.h" #include "components/variations/scoped_variations_ids_provider.h" #include "components/variations/variations_client.h" #include "content/public/test/browser_task_environment.h" #include "content/public/test/test_renderer_host.h" #include "services/network/test/test_url_loader_factory.h" #include "testing/gtest/include/gtest/gtest.h" #if defined(TOOLKIT_VIEWS) #include "chrome/test/views/chrome_test_views_delegate.h" #if BUILDFLAG(IS_CHROMEOS_ASH) #include "ash/test/ash_test_helper.h" #include "ash/test/ash_test_views_delegate.h" #include "base/scoped_observation.h" #include "chrome/browser/ash/app_mode/kiosk_chrome_app_manager.h" #include "chrome/browser/ash/settings/scoped_cros_settings_test_helper.h" #include "chromeos/ash/components/install_attributes/stub_install_attributes.h" #include "components/user_manager/fake_user_manager.h" #include "components/user_manager/scoped_user_manager.h" #else #include "ui/views/test/scoped_views_test_helper.h" #endif #endif #if BUILDFLAG(IS_WIN) #include "ui/base/win/scoped_ole_initializer.h" #endif class GURL; namespace chromeos { class ScopedLacrosServiceTestHelper; } // namespace chromeos namespace content { class NavigationController; } #if BUILDFLAG(IS_CHROMEOS_ASH) namespace crosapi { class CrosapiManager; } #endif class TestingProfileManager; // WARNING WARNING WARNING WARNING // Do not use this class. See docs/chrome_browser_design_principles.md for // details. Either write a browser test which provides both a "class Browser" // and a "class BrowserView" or a unit test which requires neither. // Historically, features were written that take a "class Browser" as an input // parameter. "class Browser" cannot be stubbed/faked/mocked, and this class was // written as a workaround to create a "class Browser" without a "class // BrowserView". This cannot happen in production code and thus results in test // logic leaking into production code. New features should not take "class // Browser" as input, and should instead perform dependency injection. // // Base class for browser based unit tests. BrowserWithTestWindowTest creates a // Browser with a TestingProfile and TestBrowserWindow. To add a tab use // AddTab. For example, the following adds a tab and navigates to two URLs: // // // Add a new tab and navigate it. This will be at index 0. // // WARNING: this creates a real WebContents. If you want to add a test // // WebContents create it directly and insert it into the TabStripModel. // AddTab(browser(), GURL("http://foo/1")); // WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); // // // Navigate somewhere else. // GURL url2("http://foo/2"); // NavigateAndCommit(contents, url2); // // // This is equivalent to the above, and lets you test pending navigations. // browser()->OpenURL(OpenURLParams( // GURL("http://foo/2"), GURL(), WindowOpenDisposition::CURRENT_TAB, // ui::PAGE_TRANSITION_TYPED, false), /*navigation_handle_callback=*/{}); // CommitPendingLoad(&contents->GetController()); // // Subclasses must invoke BrowserWithTestWindowTest::SetUp as it is responsible // for creating the various objects of this class. class BrowserWithTestWindowTest : public testing::Test, public ProfileObserver { … }; #endif // CHROME_TEST_BASE_BROWSER_WITH_TEST_WINDOW_TEST_H_