• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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.
4 
5 #include "chrome/browser/extensions/extension_apitest.h"
6 
7 #include "chrome/browser/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/common/pref_names.h"
12 #include "net/base/mock_host_resolver.h"
13 
14 // Possible race in ChromeURLDataManager. http://crbug.com/59198
15 #if defined(OS_MACOSX) || defined(OS_LINUX)
16 #define MAYBE_TabOnRemoved DISABLED_TabOnRemoved
17 #else
18 #define MAYBE_TabOnRemoved TabOnRemoved
19 #endif
20 
21 // Crashes on linux views. http://crbug.com/61592
22 #if defined(OS_LINUX) && defined(TOOLKIT_VIEWS)
23 #define MAYBE_Tabs DISABLED_Tabs
24 #else
25 #define MAYBE_Tabs Tabs
26 #endif
27 
28 // Window resizes are not completed by the time the callback happens,
29 // so these tests fail on linux. http://crbug.com/72369
30 #if defined(OS_LINUX)
31 #define MAYBE_FocusWindowDoesNotExitFullscreen \
32   DISABLED_FocusWindowDoesNotExitFullscreen
33 #define MAYBE_UpdateWindowSizeExitsFullscreen \
34   DISABLED_UpdateWindowSizeExitsFullscreen
35 #else
36 #define MAYBE_FocusWindowDoesNotExitFullscreen FocusWindowDoesNotExitFullscreen
37 #define MAYBE_UpdateWindowSizeExitsFullscreen UpdateWindowSizeExitsFullscreen
38 #endif
39 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,MAYBE_Tabs)40 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_Tabs) {
41   ASSERT_TRUE(StartTestServer());
42 
43   // The test creates a tab and checks that the URL of the new tab
44   // is that of the new tab page.  Make sure the pref that controls
45   // this is set.
46   browser()->profile()->GetPrefs()->SetBoolean(
47       prefs::kHomePageIsNewTabPage, true);
48 
49   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud.html")) << message_;
50 }
51 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,TabPinned)52 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabPinned) {
53   ASSERT_TRUE(StartTestServer());
54   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "pinned.html")) << message_;
55 }
56 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,TabMove)57 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabMove) {
58   ASSERT_TRUE(StartTestServer());
59   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "move.html")) << message_;
60 }
61 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,TabEvents)62 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabEvents) {
63   ASSERT_TRUE(StartTestServer());
64   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "events.html")) << message_;
65 }
66 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,TabRelativeURLs)67 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabRelativeURLs) {
68   ASSERT_TRUE(StartTestServer());
69   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "relative_urls.html"))
70       << message_;
71 }
72 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,TabCrashBrowser)73 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabCrashBrowser) {
74   ASSERT_TRUE(StartTestServer());
75   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crash.html")) << message_;
76 }
77 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,TabGetCurrent)78 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabGetCurrent) {
79   ASSERT_TRUE(StartTestServer());
80   ASSERT_TRUE(RunExtensionTest("tabs/get_current")) << message_;
81 }
82 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,TabConnect)83 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabConnect) {
84   ASSERT_TRUE(StartTestServer());
85   ASSERT_TRUE(RunExtensionTest("tabs/connect")) << message_;
86 }
87 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,MAYBE_TabOnRemoved)88 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabOnRemoved) {
89   ASSERT_TRUE(StartTestServer());
90   ASSERT_TRUE(RunExtensionTest("tabs/on_removed")) << message_;
91 }
92 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,CaptureVisibleTabJpeg)93 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, CaptureVisibleTabJpeg) {
94   host_resolver()->AddRule("a.com", "127.0.0.1");
95   host_resolver()->AddRule("b.com", "127.0.0.1");
96   ASSERT_TRUE(StartTestServer());
97   ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
98                                   "test_jpeg.html")) << message_;
99 }
100 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,CaptureVisibleTabPng)101 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, CaptureVisibleTabPng) {
102   host_resolver()->AddRule("a.com", "127.0.0.1");
103   host_resolver()->AddRule("b.com", "127.0.0.1");
104   ASSERT_TRUE(StartTestServer());
105   ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
106                                   "test_png.html")) << message_;
107 }
108 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,TabsOnUpdated)109 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabsOnUpdated) {
110   ASSERT_TRUE(StartTestServer());
111   ASSERT_TRUE(RunExtensionTest("tabs/on_updated")) << message_;
112 }
113 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,MAYBE_FocusWindowDoesNotExitFullscreen)114 IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
115                        MAYBE_FocusWindowDoesNotExitFullscreen) {
116   browser()->window()->SetFullscreen(true);
117   bool is_fullscreen = browser()->window()->IsFullscreen();
118   ASSERT_TRUE(RunExtensionTest("window_update/focus")) << message_;
119   ASSERT_EQ(is_fullscreen, browser()->window()->IsFullscreen());
120 }
121 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,MAYBE_UpdateWindowSizeExitsFullscreen)122 IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
123                        MAYBE_UpdateWindowSizeExitsFullscreen) {
124   browser()->window()->SetFullscreen(true);
125   ASSERT_TRUE(RunExtensionTest("window_update/sizing")) << message_;
126   ASSERT_FALSE(browser()->window()->IsFullscreen());
127 }
128 
129 #if defined(OS_WIN)
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,FocusWindowDoesNotUnmaximize)130 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FocusWindowDoesNotUnmaximize) {
131   gfx::NativeWindow window = browser()->window()->GetNativeHandle();
132   ::SendMessage(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
133   ASSERT_TRUE(RunExtensionTest("window_update/focus")) << message_;
134   ASSERT_TRUE(::IsZoomed(window));
135 }
136 #endif  // OS_WIN
137 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,IncognitoDisabledByPref)138 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabledByPref) {
139   ASSERT_TRUE(StartTestServer());
140 
141   browser()->profile()->GetPrefs()->SetBoolean(prefs::kIncognitoEnabled, false);
142 
143   // This makes sure that creating an incognito window fails due to pref
144   // (policy) being set.
145   ASSERT_TRUE(RunExtensionTest("tabs/incognito_disabled")) << message_;
146 }
147 
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,GetViewsOfCreatedPopup)148 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, GetViewsOfCreatedPopup) {
149   ASSERT_TRUE(StartTestServer());
150   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_popup.html"))
151       << message_;
152 }
IN_PROC_BROWSER_TEST_F(ExtensionApiTest,GetViewsOfCreatedWindow)153 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, GetViewsOfCreatedWindow) {
154   ASSERT_TRUE(StartTestServer());
155   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_window.html"))
156       << message_;
157 }
158