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/root_window.h"
19 #include "ui/aura/window.h"
22 // Window resizes are not completed by the time the callback happens,
23 // so these tests fail on linux/gtk. http://crbug.com/72369
24 #if defined(OS_LINUX) && !defined(USE_AURA)
25 #define MAYBE_UpdateWindowResize DISABLED_UpdateWindowResize
26 #define MAYBE_UpdateWindowShowState DISABLED_UpdateWindowShowState
29 #if defined(USE_AURA) || defined(OS_MACOSX)
30 // Maximizing/fullscreen popup window doesn't work on aura's managed mode.
31 // See bug crbug.com/116305.
32 // Mac: http://crbug.com/103912
33 #define MAYBE_UpdateWindowShowState DISABLED_UpdateWindowShowState
35 #define MAYBE_UpdateWindowShowState UpdateWindowShowState
36 #endif // defined(USE_AURA) || defined(OS_MACOSX)
38 #define MAYBE_UpdateWindowResize UpdateWindowResize
39 #endif // defined(OS_LINUX) && !defined(USE_AURA)
41 // http://crbug.com/145639
42 #if defined(OS_LINUX) || defined(OS_WIN)
43 #define MAYBE_TabEvents DISABLED_TabEvents
45 #define MAYBE_TabEvents TabEvents
48 class ExtensionApiNewTabTest
: public ExtensionApiTest
{
50 ExtensionApiNewTabTest() {}
51 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
52 ExtensionApiTest::SetUpCommandLine(command_line
);
53 // Override the default which InProcessBrowserTest adds if it doesn't see a
55 command_line
->AppendSwitchASCII(
56 switches::kHomePage
, chrome::kChromeUINewTabURL
);
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 // Flaky on windows: http://crbug.com/238667
72 #define MAYBE_Tabs2 DISABLED_Tabs2
74 #define MAYBE_Tabs2 Tabs2
76 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_Tabs2
) {
77 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud2.html")) << message_
;
81 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabDuplicate
) {
82 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "duplicate.html")) << message_
;
85 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabSize
) {
86 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "tab_size.html")) << message_
;
89 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabUpdate
) {
90 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "update.html")) << message_
;
93 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabPinned
) {
94 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "pinned.html")) << message_
;
97 // Flaky on windows: http://crbug.com/238667
99 #define MAYBE_TabMove DISABLED_TabMove
101 #define MAYBE_TabMove TabMove
103 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_TabMove
) {
104 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "move.html")) << message_
;
107 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_TabEvents
) {
108 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "events.html")) << message_
;
111 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabRelativeURLs
) {
112 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "relative_urls.html"))
116 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabQuery
) {
117 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "query.html")) << message_
;
120 // Flaky on windows: http://crbug.com/239022
122 #define MAYBE_TabHighlight DISABLED_TabHighlight
124 #define MAYBE_TabHighlight TabHighlight
126 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_TabHighlight
) {
127 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "highlight.html")) << message_
;
130 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabCrashBrowser
) {
131 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crash.html")) << message_
;
134 // Flaky on windows: http://crbug.com/238667
136 #define MAYBE_TabOpener DISABLED_TabOpener
138 #define MAYBE_TabOpener TabOpener
140 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_TabOpener
) {
141 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "opener.html")) << message_
;
144 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabGetCurrent
) {
145 ASSERT_TRUE(RunExtensionTest("tabs/get_current")) << message_
;
148 // Flaky on the trybots. See http://crbug.com/96725.
149 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabConnect
) {
150 ASSERT_TRUE(StartEmbeddedTestServer());
151 ASSERT_TRUE(RunExtensionTest("tabs/connect")) << message_
;
154 // Possible race in ChromeURLDataManager. http://crbug.com/59198
155 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabOnRemoved
) {
156 ASSERT_TRUE(RunExtensionTest("tabs/on_removed")) << message_
;
159 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_TabReload
) {
160 ASSERT_TRUE(RunExtensionTest("tabs/reload")) << message_
;
163 class ExtensionApiCaptureTest
: public ExtensionApiTest
{
165 ExtensionApiCaptureTest() {}
166 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
168 ExtensionApiTest::SetUpCommandLine(command_line
);
172 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
,
173 DISABLED_CaptureVisibleTabJpeg
) {
174 host_resolver()->AddRule("a.com", "127.0.0.1");
175 host_resolver()->AddRule("b.com", "127.0.0.1");
176 ASSERT_TRUE(StartEmbeddedTestServer());
177 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
178 "test_jpeg.html")) << message_
;
181 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
, DISABLED_CaptureVisibleTabPng
) {
182 host_resolver()->AddRule("a.com", "127.0.0.1");
183 host_resolver()->AddRule("b.com", "127.0.0.1");
184 ASSERT_TRUE(StartEmbeddedTestServer());
185 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
186 "test_png.html")) << message_
;
189 // Times out on non-Windows.
190 // See http://crbug.com/80212
191 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
,
192 DISABLED_CaptureVisibleTabRace
) {
193 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
194 "test_race.html")) << message_
;
197 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
, CaptureVisibleFile
) {
198 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
199 "test_file.html")) << message_
;
202 // Flaky on windows: http://crbug.com/238667
204 #define MAYBE_CaptureVisibleNoFile DISABLED_CaptureVisibleNoFile
206 #define MAYBE_CaptureVisibleNoFile CaptureVisibleNoFile
208 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
, MAYBE_CaptureVisibleNoFile
) {
209 ASSERT_TRUE(RunExtensionSubtest(
210 "tabs/capture_visible_tab", "test_nofile.html",
211 ExtensionApiTest::kFlagNone
)) << message_
;
214 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest
, CaptureVisibleDisabled
) {
215 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDisableScreenshots
,
217 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
218 "test_disabled.html")) << message_
;
221 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabsOnUpdated
) {
222 ASSERT_TRUE(RunExtensionTest("tabs/on_updated")) << message_
;
225 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, TabsNoPermissions
) {
226 ASSERT_TRUE(RunExtensionTest("tabs/no_permissions")) << message_
;
229 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
,
230 MAYBE_UpdateWindowResize
) {
231 ASSERT_TRUE(RunExtensionTest("window_update/resize")) << message_
;
235 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, FocusWindowDoesNotUnmaximize
) {
236 HWND window
= browser()->window()->GetNativeWindow()->
237 GetDispatcher()->host()->GetAcceleratedWidget();
238 ::SendMessage(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
239 ASSERT_TRUE(RunExtensionTest("window_update/focus")) << message_
;
240 ASSERT_TRUE(::IsZoomed(window
));
244 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, MAYBE_UpdateWindowShowState
) {
245 ASSERT_TRUE(RunExtensionTest("window_update/show_state")) << message_
;
248 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, IncognitoDisabledByPref
) {
249 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
250 IncognitoModePrefs::DISABLED
);
252 // This makes sure that creating an incognito window fails due to pref
253 // (policy) being set.
254 ASSERT_TRUE(RunExtensionTest("tabs/incognito_disabled")) << message_
;
257 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_GetViewsOfCreatedPopup
) {
258 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_popup.html"))
261 IN_PROC_BROWSER_TEST_F(ExtensionApiTest
, DISABLED_GetViewsOfCreatedWindow
) {
262 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_window.html"))
266 // Adding a new test? Awesome. But API tests are the old hotness. The
267 // new hotness is extension_test_utils. See tabs_test.cc for an example.
268 // We are trying to phase out many uses of API tests as they tend to be flaky.