1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/prefs/incognito_mode_prefs.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/pref_names.h"
14 #include "chrome/common/url_constants.h"
15 #include "net/dns/mock_host_resolver.h"
18 #include "ui/aura/window.h"
19 #include "ui/aura/window_tree_host.h"
22 #if defined(USE_AURA) || defined(OS_MACOSX)
23 // Maximizing/fullscreen popup window doesn't work on aura's managed mode.
24 // See bug crbug.com/116305.
25 // Mac: http://crbug.com/103912
26 #define MAYBE_UpdateWindowShowState DISABLED_UpdateWindowShowState
28 #define MAYBE_UpdateWindowShowState UpdateWindowShowState
29 #endif // defined(USE_AURA) || defined(OS_MACOSX)
31 // http://crbug.com/145639
32 #if defined(OS_LINUX) || defined(OS_WIN)
33 #define MAYBE_TabEvents DISABLED_TabEvents
35 #define MAYBE_TabEvents TabEvents
38 class ExtensionApiNewTabTest
: public ExtensionApiTest
{
40 ExtensionApiNewTabTest() {}
41 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
42 ExtensionApiTest::SetUpCommandLine(command_line
);
43 // Override the default which InProcessBrowserTest adds if it doesn't see a
45 command_line
->AppendSwitchASCII(
46 switches::kHomePage
, chrome::kChromeUINewTabURL
);
50 class ExtensionApiTabAudioMutingTest
: public ExtensionApiTest
{
52 ExtensionApiTabAudioMutingTest() {}
53 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
54 ExtensionApiTest::SetUpCommandLine(command_line
);
56 command_line
->AppendSwitch(switches::kEnableTabAudioMuting
);
60 IN_PROC_BROWSER_TEST_F(ExtensionApiNewTabTest
, Tabs
) {
61 // The test creates a tab and checks that the URL of the new tab
62 // is that of the new tab page. Make sure the pref that controls
64 browser()->profile()->GetPrefs()->SetBoolean(
65 prefs::kHomePageIsNewTabPage
, true);
67 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud.html")) << message_
;
70 IN_PROC_BROWSER_TEST_F(ExtensionApiTabAudioMutingTest
, TabAudible
) {
71 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "audible.html")) << message_
;
74 IN_PROC_BROWSER_TEST_F(ExtensionApiTabAudioMutingTest
, TabMuted
) {
75 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "muted.html")) << message_
;
78 // Flaky on windows: http://crbug.com/238667
80 #define MAYBE_Tabs2 DISABLED_Tabs2
82 #define MAYBE_Tabs2 Tabs2
84 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_Tabs2
) {
85 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud2.html")) << message_
;
89 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabDuplicate
) {
90 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "duplicate.html")) << message_
;
93 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabSize
) {
94 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "tab_size.html")) << message_
;
97 // Flaky on linux: http://crbug.com/396364
99 #define MAYBE_TabUpdate DISABLED_TabUpdate
101 #define MAYBE_TabUpdate TabUpdate
103 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_TabUpdate
) {
104 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "update.html")) << message_
;
107 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabPinned
) {
108 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "pinned.html")) << message_
;
111 // Flaky on windows: http://crbug.com/238667
113 #define MAYBE_TabMove DISABLED_TabMove
115 #define MAYBE_TabMove TabMove
117 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_TabMove
) {
118 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "move.html")) << message_
;
121 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_TabEvents
) {
122 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "events.html")) << message_
;
125 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabRelativeURLs
) {
126 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "relative_urls.html"))
130 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabQuery
) {
131 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "query.html")) << message_
;
134 // Flaky on windows: http://crbug.com/239022
136 #define MAYBE_TabHighlight DISABLED_TabHighlight
138 #define MAYBE_TabHighlight TabHighlight
140 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_TabHighlight
) {
141 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "highlight.html")) << message_
;
144 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabCrashBrowser
) {
145 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crash.html")) << message_
;
148 // Flaky on windows: http://crbug.com/238667
150 #define MAYBE_TabOpener DISABLED_TabOpener
152 #define MAYBE_TabOpener TabOpener
154 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_TabOpener
) {
155 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "opener.html")) << message_
;
158 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabGetCurrent
) {
159 ASSERT_TRUE(RunExtensionTest("tabs/get_current")) << message_
;
162 // Flaky on the trybots. See http://crbug.com/96725.
163 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabConnect
) {
164 ASSERT_TRUE(StartEmbeddedTestServer());
165 ASSERT_TRUE(RunExtensionTest("tabs/connect")) << message_
;
168 // Possible race in ChromeURLDataManager. http://crbug.com/59198
169 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabOnRemoved
) {
170 ASSERT_TRUE(RunExtensionTest("tabs/on_removed")) << message_
;
173 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabReload
) {
174 ASSERT_TRUE(RunExtensionTest("tabs/reload")) << message_
;
177 class ExtensionApiCaptureTest
: public ExtensionApiTest
{
179 ExtensionApiCaptureTest() {}
181 void SetUp() override
{
183 ExtensionApiTest::SetUp();
186 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
187 ExtensionApiTest::SetUpCommandLine(command_line
);
191 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
,
192 DISABLED_CaptureVisibleTabJpeg
) {
193 host_resolver()->AddRule("a.com", "127.0.0.1");
194 host_resolver()->AddRule("b.com", "127.0.0.1");
195 ASSERT_TRUE(StartEmbeddedTestServer());
196 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
197 "test_jpeg.html")) << message_
;
200 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
, DISABLED_CaptureVisibleTabPng
) {
201 host_resolver()->AddRule("a.com", "127.0.0.1");
202 host_resolver()->AddRule("b.com", "127.0.0.1");
203 ASSERT_TRUE(StartEmbeddedTestServer());
204 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
205 "test_png.html")) << message_
;
208 // Times out on non-Windows.
209 // See http://crbug.com/80212
210 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
,
211 DISABLED_CaptureVisibleTabRace
) {
212 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
213 "test_race.html")) << message_
;
217 // Disabled for being flaky, see http://crbug/367695.
218 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
,
219 DISABLED_CaptureVisibleFile
) {
220 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
221 "test_file.html")) << message_
;
224 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
, CaptureVisibleDisabled
) {
225 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDisableScreenshots
,
227 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
228 "test_disabled.html")) << message_
;
231 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabsOnUpdated
) {
232 ASSERT_TRUE(RunExtensionTest("tabs/on_updated")) << message_
;
235 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabsNoPermissions
) {
236 ASSERT_TRUE(RunExtensionTest("tabs/no_permissions")) << message_
;
239 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, UpdateWindowResize
) {
240 ASSERT_TRUE(RunExtensionTest("window_update/resize")) << message_
;
244 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, FocusWindowDoesNotUnmaximize
) {
246 browser()->window()->GetNativeWindow()->GetHost()->GetAcceleratedWidget();
247 ::SendMessage(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
248 ASSERT_TRUE(RunExtensionTest("window_update/focus")) << message_
;
249 ASSERT_TRUE(::IsZoomed(window
));
253 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_UpdateWindowShowState
) {
254 ASSERT_TRUE(RunExtensionTest("window_update/show_state")) << message_
;
257 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, IncognitoDisabledByPref
) {
258 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
259 IncognitoModePrefs::DISABLED
);
261 // This makes sure that creating an incognito window fails due to pref
262 // (policy) being set.
263 ASSERT_TRUE(RunExtensionTest("tabs/incognito_disabled")) << message_
;
266 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_GetViewsOfCreatedPopup
) {
267 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_popup.html"))
270 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_GetViewsOfCreatedWindow
) {
271 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_window.html"))
275 // Adding a new test? Awesome. But API tests are the old hotness. The new
276 // hotness is extension_function_test_utils. See tabs_test.cc for an example.
277 // We are trying to phase out many uses of API tests as they tend to be flaky.