Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / extensions / extension_tabs_apitest.cc
blob4fdeb3585a36741c6cf779f2c3ba455860ac5850
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/window.h"
19 #include "ui/aura/window_tree_host.h"
20 #endif
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
27 #else
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
34 #else
35 #define MAYBE_TabEvents TabEvents
36 #endif
38 class ExtensionApiNewTabTest : public ExtensionApiTest {
39 public:
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
44 // homepage.
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
53 // this is set.
54 browser()->profile()->GetPrefs()->SetBoolean(
55 prefs::kHomePageIsNewTabPage, true);
57 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud.html")) << message_;
60 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabAudible) {
61 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "audible.html")) << message_;
64 // http://crbug.com/521410
65 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_TabMuted) {
66 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "muted.html")) << message_;
69 // Flaky on windows: http://crbug.com/238667
70 #if defined(OS_WIN)
71 #define MAYBE_Tabs2 DISABLED_Tabs2
72 #else
73 #define MAYBE_Tabs2 Tabs2
74 #endif
75 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_Tabs2) {
76 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud2.html")) << message_;
79 // crbug.com/149924
80 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_TabDuplicate) {
81 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "duplicate.html")) << message_;
84 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabSize) {
85 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "tab_size.html")) << message_;
88 // Flaky on linux: http://crbug.com/396364
89 #if defined(OS_LINUX)
90 #define MAYBE_TabUpdate DISABLED_TabUpdate
91 #else
92 #define MAYBE_TabUpdate TabUpdate
93 #endif
94 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabUpdate) {
95 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "update.html")) << message_;
98 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabPinned) {
99 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "pinned.html")) << message_;
102 // Flaky on windows: http://crbug.com/238667
103 #if defined(OS_WIN)
104 #define MAYBE_TabMove DISABLED_TabMove
105 #else
106 #define MAYBE_TabMove TabMove
107 #endif
108 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabMove) {
109 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "move.html")) << message_;
112 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabEvents) {
113 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "events.html")) << message_;
116 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_TabRelativeURLs) {
117 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "relative_urls.html"))
118 << message_;
121 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabQuery) {
122 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "query.html")) << message_;
125 // Flaky on windows: http://crbug.com/239022
126 #if defined(OS_WIN)
127 #define MAYBE_TabHighlight DISABLED_TabHighlight
128 #else
129 #define MAYBE_TabHighlight TabHighlight
130 #endif
131 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabHighlight) {
132 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "highlight.html")) << message_;
135 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabCrashBrowser) {
136 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crash.html")) << message_;
139 // Flaky on windows: http://crbug.com/238667
140 #if defined(OS_WIN)
141 #define MAYBE_TabOpener DISABLED_TabOpener
142 #else
143 #define MAYBE_TabOpener TabOpener
144 #endif
145 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabOpener) {
146 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "opener.html")) << message_;
149 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_TabGetCurrent) {
150 ASSERT_TRUE(RunExtensionTest("tabs/get_current")) << message_;
153 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabConnect) {
154 ASSERT_TRUE(StartEmbeddedTestServer());
155 ASSERT_TRUE(RunExtensionTest("tabs/connect")) << message_;
158 // Possible race in ChromeURLDataManager. http://crbug.com/59198
159 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_TabOnRemoved) {
160 ASSERT_TRUE(RunExtensionTest("tabs/on_removed")) << message_;
163 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_TabReload) {
164 ASSERT_TRUE(RunExtensionTest("tabs/reload")) << message_;
167 class ExtensionApiCaptureTest : public ExtensionApiTest {
168 public:
169 ExtensionApiCaptureTest() {}
171 void SetUp() override {
172 EnablePixelOutput();
173 ExtensionApiTest::SetUp();
176 void SetUpCommandLine(base::CommandLine* command_line) override {
177 ExtensionApiTest::SetUpCommandLine(command_line);
181 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest,
182 DISABLED_CaptureVisibleTabJpeg) {
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_jpeg.html")) << message_;
190 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest, DISABLED_CaptureVisibleTabPng) {
191 host_resolver()->AddRule("a.com", "127.0.0.1");
192 host_resolver()->AddRule("b.com", "127.0.0.1");
193 ASSERT_TRUE(StartEmbeddedTestServer());
194 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
195 "test_png.html")) << message_;
198 // Times out on non-Windows.
199 // See http://crbug.com/80212
200 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest,
201 DISABLED_CaptureVisibleTabRace) {
202 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
203 "test_race.html")) << message_;
207 // Disabled for being flaky, see http://crbug/367695.
208 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest,
209 DISABLED_CaptureVisibleFile) {
210 ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
211 "test_file.html")) << message_;
214 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest, CaptureVisibleDisabled) {
215 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDisableScreenshots,
216 true);
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, UpdateWindowResize) {
230 ASSERT_TRUE(RunExtensionTest("window_update/resize")) << message_;
233 #if defined(OS_WIN)
234 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FocusWindowDoesNotUnmaximize) {
235 HWND window =
236 browser()->window()->GetNativeWindow()->GetHost()->GetAcceleratedWidget();
237 ::SendMessage(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
238 ASSERT_TRUE(RunExtensionTest("window_update/focus")) << message_;
239 ASSERT_TRUE(::IsZoomed(window));
241 #endif // OS_WIN
243 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_UpdateWindowShowState) {
244 ASSERT_TRUE(RunExtensionTest("window_update/show_state")) << message_;
247 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabledByPref) {
248 IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
249 IncognitoModePrefs::DISABLED);
251 // This makes sure that creating an incognito window fails due to pref
252 // (policy) being set.
253 ASSERT_TRUE(RunExtensionTest("tabs/incognito_disabled")) << message_;
256 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_GetViewsOfCreatedPopup) {
257 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_popup.html"))
258 << message_;
260 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_GetViewsOfCreatedWindow) {
261 ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_window.html"))
262 << message_;
265 // Adding a new test? Awesome. But API tests are the old hotness. The new
266 // hotness is extension_function_test_utils. See tabs_test.cc for an example.
267 // We are trying to phase out many uses of API tests as they tend to be flaky.