NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / extensions / extension_tabs_apitest.cc
blobf3e16e926c0d915a71eebaea48b625936af87b75
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"
17 #if defined(OS_WIN)
18 #include "ui/aura/root_window.h"
19 #include "ui/aura/window.h"
20 #endif
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
27 #else
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
34 #else
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
44 #else
45 #define MAYBE_TabEvents TabEvents
46 #endif
48 class ExtensionApiNewTabTest : public ExtensionApiTest {
49 public:
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
54 // homepage.
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
63 // this is set.
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
71 #if defined(OS_WIN)
72 #define MAYBE_Tabs2 DISABLED_Tabs2
73 #else
74 #define MAYBE_Tabs2 Tabs2
75 #endif
76 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_Tabs2) {
77 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud2.html")) << message_;
80 // crbug.com/149924
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
98 #if defined(OS_WIN)
99 #define MAYBE_TabMove DISABLED_TabMove
100 #else
101 #define MAYBE_TabMove TabMove
102 #endif
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"))
113 << message_;
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
121 #if defined(OS_WIN)
122 #define MAYBE_TabHighlight DISABLED_TabHighlight
123 #else
124 #define MAYBE_TabHighlight TabHighlight
125 #endif
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
135 #if defined(OS_WIN)
136 #define MAYBE_TabOpener DISABLED_TabOpener
137 #else
138 #define MAYBE_TabOpener TabOpener
139 #endif
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 {
164 public:
165 ExtensionApiCaptureTest() {}
167 virtual void SetUp() OVERRIDE {
168 EnablePixelOutput();
169 ExtensionApiTest::SetUp();
172 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
173 ExtensionApiTest::SetUpCommandLine(command_line);
177 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest,
178 DISABLED_CaptureVisibleTabJpeg) {
179 host_resolver()->AddRule("a.com", "127.0.0.1");
180 host_resolver()->AddRule("b.com", "127.0.0.1");
181 ASSERT_TRUE(StartEmbeddedTestServer());
182 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
183 "test_jpeg.html")) << message_;
186 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest, DISABLED_CaptureVisibleTabPng) {
187 host_resolver()->AddRule("a.com", "127.0.0.1");
188 host_resolver()->AddRule("b.com", "127.0.0.1");
189 ASSERT_TRUE(StartEmbeddedTestServer());
190 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
191 "test_png.html")) << message_;
194 // Times out on non-Windows.
195 // See http://crbug.com/80212
196 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest,
197 DISABLED_CaptureVisibleTabRace) {
198 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
199 "test_race.html")) << message_;
202 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest, CaptureVisibleFile) {
203 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
204 "test_file.html")) << message_;
207 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest, CaptureVisibleDisabled) {
208 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDisableScreenshots,
209 true);
210 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
211 "test_disabled.html")) << message_;
214 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabsOnUpdated) {
215 ASSERT_TRUE(RunExtensionTest("tabs/on_updated")) << message_;
218 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabsNoPermissions) {
219 ASSERT_TRUE(RunExtensionTest("tabs/no_permissions")) << message_;
222 IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
223 MAYBE_UpdateWindowResize) {
224 ASSERT_TRUE(RunExtensionTest("window_update/resize")) << message_;
227 #if defined(OS_WIN)
228 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FocusWindowDoesNotUnmaximize) {
229 HWND window = browser()->window()->GetNativeWindow()->
230 GetDispatcher()->host()->GetAcceleratedWidget();
231 ::SendMessage(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
232 ASSERT_TRUE(RunExtensionTest("window_update/focus")) << message_;
233 ASSERT_TRUE(::IsZoomed(window));
235 #endif // OS_WIN
237 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_UpdateWindowShowState) {
238 ASSERT_TRUE(RunExtensionTest("window_update/show_state")) << message_;
241 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabledByPref) {
242 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
243 IncognitoModePrefs::DISABLED);
245 // This makes sure that creating an incognito window fails due to pref
246 // (policy) being set.
247 ASSERT_TRUE(RunExtensionTest("tabs/incognito_disabled")) << message_;
250 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_GetViewsOfCreatedPopup) {
251 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_popup.html"))
252 << message_;
254 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_GetViewsOfCreatedWindow) {
255 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_window.html"))
256 << message_;
259 // Adding a new test? Awesome. But API tests are the old hotness. The
260 // new hotness is extension_test_utils. See tabs_test.cc for an example.
261 // We are trying to phase out many uses of API tests as they tend to be flaky.