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(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 IN_PROC_BROWSER_TEST_F(ExtensionApiNewTabTest
, Tabs
) {
51 // The test creates a tab and checks that the URL of the new tab
52 // is that of the new tab page. Make sure the pref that controls
54 browser()->profile()->GetPrefs()->SetBoolean(
55 prefs::kHomePageIsNewTabPage
, true);
57 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud.html")) << message_
;
60 // Flaky on windows: http://crbug.com/238667
62 #define MAYBE_Tabs2 DISABLED_Tabs2
64 #define MAYBE_Tabs2 Tabs2
66 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_Tabs2
) {
67 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud2.html")) << message_
;
71 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabDuplicate
) {
72 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "duplicate.html")) << message_
;
75 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabSize
) {
76 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "tab_size.html")) << message_
;
79 // Flaky on linux: http://crbug.com/396364
81 #define MAYBE_TabUpdate DISABLED_TabUpdate
83 #define MAYBE_TabUpdate TabUpdate
85 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_TabUpdate
) {
86 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "update.html")) << message_
;
89 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabPinned
) {
90 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "pinned.html")) << message_
;
93 // Flaky on windows: http://crbug.com/238667
95 #define MAYBE_TabMove DISABLED_TabMove
97 #define MAYBE_TabMove TabMove
99 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_TabMove
) {
100 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "move.html")) << message_
;
103 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_TabEvents
) {
104 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "events.html")) << message_
;
107 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabRelativeURLs
) {
108 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "relative_urls.html"))
112 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabQuery
) {
113 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "query.html")) << message_
;
116 // Flaky on windows: http://crbug.com/239022
118 #define MAYBE_TabHighlight DISABLED_TabHighlight
120 #define MAYBE_TabHighlight TabHighlight
122 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_TabHighlight
) {
123 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "highlight.html")) << message_
;
126 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabCrashBrowser
) {
127 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crash.html")) << message_
;
130 // Flaky on windows: http://crbug.com/238667
132 #define MAYBE_TabOpener DISABLED_TabOpener
134 #define MAYBE_TabOpener TabOpener
136 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_TabOpener
) {
137 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "opener.html")) << message_
;
140 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabGetCurrent
) {
141 ASSERT_TRUE(RunExtensionTest("tabs/get_current")) << message_
;
144 // Flaky on the trybots. See http://crbug.com/96725.
145 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabConnect
) {
146 ASSERT_TRUE(StartEmbeddedTestServer());
147 ASSERT_TRUE(RunExtensionTest("tabs/connect")) << message_
;
150 // Possible race in ChromeURLDataManager. http://crbug.com/59198
151 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabOnRemoved
) {
152 ASSERT_TRUE(RunExtensionTest("tabs/on_removed")) << message_
;
155 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabReload
) {
156 ASSERT_TRUE(RunExtensionTest("tabs/reload")) << message_
;
159 class ExtensionApiCaptureTest
: public ExtensionApiTest
{
161 ExtensionApiCaptureTest() {}
163 virtual void SetUp() override
{
165 ExtensionApiTest::SetUp();
168 void SetUpCommandLine(CommandLine
* command_line
) override
{
169 ExtensionApiTest::SetUpCommandLine(command_line
);
173 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
,
174 DISABLED_CaptureVisibleTabJpeg
) {
175 host_resolver()->AddRule("a.com", "127.0.0.1");
176 host_resolver()->AddRule("b.com", "127.0.0.1");
177 ASSERT_TRUE(StartEmbeddedTestServer());
178 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
179 "test_jpeg.html")) << message_
;
182 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
, DISABLED_CaptureVisibleTabPng
) {
183 host_resolver()->AddRule("a.com", "127.0.0.1");
184 host_resolver()->AddRule("b.com", "127.0.0.1");
185 ASSERT_TRUE(StartEmbeddedTestServer());
186 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
187 "test_png.html")) << message_
;
190 // Times out on non-Windows.
191 // See http://crbug.com/80212
192 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
,
193 DISABLED_CaptureVisibleTabRace
) {
194 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
195 "test_race.html")) << message_
;
199 // Disabled for being flaky, see http://crbug/367695.
200 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
,
201 DISABLED_CaptureVisibleFile
) {
202 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
203 "test_file.html")) << message_
;
206 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
, CaptureVisibleDisabled
) {
207 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDisableScreenshots
,
209 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
210 "test_disabled.html")) << message_
;
213 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabsOnUpdated
) {
214 ASSERT_TRUE(RunExtensionTest("tabs/on_updated")) << message_
;
217 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabsNoPermissions
) {
218 ASSERT_TRUE(RunExtensionTest("tabs/no_permissions")) << message_
;
221 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, UpdateWindowResize
) {
222 ASSERT_TRUE(RunExtensionTest("window_update/resize")) << message_
;
226 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, FocusWindowDoesNotUnmaximize
) {
228 browser()->window()->GetNativeWindow()->GetHost()->GetAcceleratedWidget();
229 ::SendMessage(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
230 ASSERT_TRUE(RunExtensionTest("window_update/focus")) << message_
;
231 ASSERT_TRUE(::IsZoomed(window
));
235 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_UpdateWindowShowState
) {
236 ASSERT_TRUE(RunExtensionTest("window_update/show_state")) << message_
;
239 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, IncognitoDisabledByPref
) {
240 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
241 IncognitoModePrefs::DISABLED
);
243 // This makes sure that creating an incognito window fails due to pref
244 // (policy) being set.
245 ASSERT_TRUE(RunExtensionTest("tabs/incognito_disabled")) << message_
;
248 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_GetViewsOfCreatedPopup
) {
249 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_popup.html"))
252 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_GetViewsOfCreatedWindow
) {
253 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_window.html"))
257 // Adding a new test? Awesome. But API tests are the old hotness. The
258 // new hotness is extension_test_utils. See tabs_test.cc for an example.
259 // We are trying to phase out many uses of API tests as they tend to be flaky.