Home | History | Annotate | Download | only in extensions
      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.
      4 
      5 #include "chrome/browser/extensions/extension_apitest.h"
      6 
      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"
     16 
     17 
     18 // Window resizes are not completed by the time the callback happens,
     19 // so these tests fail on linux/gtk. http://crbug.com/72369
     20 #if defined(OS_LINUX) && !defined(USE_AURA)
     21 #define MAYBE_UpdateWindowResize DISABLED_UpdateWindowResize
     22 #define MAYBE_UpdateWindowShowState DISABLED_UpdateWindowShowState
     23 #else
     24 
     25 #if defined(USE_AURA) || defined(OS_MACOSX)
     26 // Maximizing/fullscreen popup window doesn't work on aura's managed mode.
     27 // See bug crbug.com/116305.
     28 // Mac: http://crbug.com/103912
     29 #define MAYBE_UpdateWindowShowState DISABLED_UpdateWindowShowState
     30 #else
     31 #define MAYBE_UpdateWindowShowState UpdateWindowShowState
     32 #endif  // defined(USE_AURA) || defined(OS_MACOSX)
     33 
     34 #define MAYBE_UpdateWindowResize UpdateWindowResize
     35 #endif  // defined(OS_LINUX) && !defined(USE_AURA)
     36 
     37 // http://crbug.com/145639
     38 #if defined(OS_LINUX) || defined(OS_WIN)
     39 #define MAYBE_TabEvents DISABLED_TabEvents
     40 #else
     41 #define MAYBE_TabEvents TabEvents
     42 #endif
     43 
     44 class ExtensionApiNewTabTest : public ExtensionApiTest {
     45  public:
     46   ExtensionApiNewTabTest() {}
     47   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
     48     ExtensionApiTest::SetUpCommandLine(command_line);
     49     // Override the default which InProcessBrowserTest adds if it doesn't see a
     50     // homepage.
     51     command_line->AppendSwitchASCII(
     52         switches::kHomePage, chrome::kChromeUINewTabURL);
     53   }
     54 };
     55 
     56 IN_PROC_BROWSER_TEST_F(ExtensionApiNewTabTest, Tabs) {
     57   // The test creates a tab and checks that the URL of the new tab
     58   // is that of the new tab page.  Make sure the pref that controls
     59   // this is set.
     60   browser()->profile()->GetPrefs()->SetBoolean(
     61       prefs::kHomePageIsNewTabPage, true);
     62 
     63   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud.html")) << message_;
     64 }
     65 
     66 // Flaky on windows: http://crbug.com/238667
     67 #if defined(OS_WIN)
     68 #define MAYBE_Tabs2 DISABLED_Tabs2
     69 #else
     70 #define MAYBE_Tabs2 Tabs2
     71 #endif
     72 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_Tabs2) {
     73   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crud2.html")) << message_;
     74 }
     75 
     76 // crbug.com/149924
     77 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_TabDuplicate) {
     78   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "duplicate.html")) << message_;
     79 }
     80 
     81 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabSize) {
     82   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "tab_size.html")) << message_;
     83 }
     84 
     85 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabUpdate) {
     86   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "update.html")) << message_;
     87 }
     88 
     89 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabPinned) {
     90   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "pinned.html")) << message_;
     91 }
     92 
     93 // Flaky on windows: http://crbug.com/238667
     94 #if defined(OS_WIN)
     95 #define MAYBE_TabMove DISABLED_TabMove
     96 #else
     97 #define MAYBE_TabMove TabMove
     98 #endif
     99 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabMove) {
    100   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "move.html")) << message_;
    101 }
    102 
    103 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabEvents) {
    104   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "events.html")) << message_;
    105 }
    106 
    107 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_TabRelativeURLs) {
    108   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "relative_urls.html"))
    109       << message_;
    110 }
    111 
    112 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabQuery) {
    113   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "query.html")) << message_;
    114 }
    115 
    116 // Flaky on windows: http://crbug.com/239022
    117 #if defined(OS_WIN)
    118 #define MAYBE_TabHighlight DISABLED_TabHighlight
    119 #else
    120 #define MAYBE_TabHighlight TabHighlight
    121 #endif
    122 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabHighlight) {
    123   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "highlight.html")) << message_;
    124 }
    125 
    126 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabCrashBrowser) {
    127   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "crash.html")) << message_;
    128 }
    129 
    130 // Flaky on windows: http://crbug.com/238667
    131 #if defined(OS_WIN)
    132 #define MAYBE_TabOpener DISABLED_TabOpener
    133 #else
    134 #define MAYBE_TabOpener TabOpener
    135 #endif
    136 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_TabOpener) {
    137   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "opener.html")) << message_;
    138 }
    139 
    140 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_TabGetCurrent) {
    141   ASSERT_TRUE(RunExtensionTest("tabs/get_current")) << message_;
    142 }
    143 
    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_;
    148 }
    149 
    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_;
    153 }
    154 
    155 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_TabReload) {
    156   ASSERT_TRUE(RunExtensionTest("tabs/reload")) << message_;
    157 }
    158 
    159 class ExtensionApiCaptureTest : public ExtensionApiTest {
    160  public:
    161   ExtensionApiCaptureTest() {}
    162   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
    163     UseRealGLContexts();
    164     ExtensionApiTest::SetUpCommandLine(command_line);
    165   }
    166 };
    167 
    168 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest,
    169                        DISABLED_CaptureVisibleTabJpeg) {
    170   host_resolver()->AddRule("a.com", "127.0.0.1");
    171   host_resolver()->AddRule("b.com", "127.0.0.1");
    172   ASSERT_TRUE(StartEmbeddedTestServer());
    173   ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
    174                                   "test_jpeg.html")) << message_;
    175 }
    176 
    177 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest, DISABLED_CaptureVisibleTabPng) {
    178   host_resolver()->AddRule("a.com", "127.0.0.1");
    179   host_resolver()->AddRule("b.com", "127.0.0.1");
    180   ASSERT_TRUE(StartEmbeddedTestServer());
    181   ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
    182                                   "test_png.html")) << message_;
    183 }
    184 
    185 // Times out on non-Windows.
    186 // See http://crbug.com/80212
    187 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest,
    188                        DISABLED_CaptureVisibleTabRace) {
    189   ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
    190                                   "test_race.html")) << message_;
    191 }
    192 
    193 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest, CaptureVisibleFile) {
    194   ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
    195                                   "test_file.html")) << message_;
    196 }
    197 
    198 // Flaky on windows: http://crbug.com/238667
    199 #if defined(OS_WIN)
    200 #define MAYBE_CaptureVisibleNoFile DISABLED_CaptureVisibleNoFile
    201 #else
    202 #define MAYBE_CaptureVisibleNoFile CaptureVisibleNoFile
    203 #endif
    204 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest, MAYBE_CaptureVisibleNoFile) {
    205   ASSERT_TRUE(RunExtensionSubtest(
    206       "tabs/capture_visible_tab", "test_nofile.html",
    207       ExtensionApiTest::kFlagNone)) << message_;
    208 }
    209 
    210 IN_PROC_BROWSER_TEST_F(ExtensionApiCaptureTest, CaptureVisibleDisabled) {
    211   browser()->profile()->GetPrefs()->SetBoolean(prefs::kDisableScreenshots,
    212                                                true);
    213   ASSERT_TRUE(RunExtensionSubtest("tabs/capture_visible_tab",
    214                                   "test_disabled.html")) << message_;
    215 }
    216 
    217 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabsOnUpdated) {
    218   ASSERT_TRUE(RunExtensionTest("tabs/on_updated")) << message_;
    219 }
    220 
    221 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, TabsNoPermissions) {
    222   ASSERT_TRUE(RunExtensionTest("tabs/no_permissions")) << message_;
    223 }
    224 
    225 IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
    226                        MAYBE_UpdateWindowResize) {
    227   ASSERT_TRUE(RunExtensionTest("window_update/resize")) << message_;
    228 }
    229 
    230 #if defined(OS_WIN) && !defined(USE_AURA)
    231 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FocusWindowDoesNotUnmaximize) {
    232   gfx::NativeWindow window = browser()->window()->GetNativeWindow();
    233   ::SendMessage(window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
    234   ASSERT_TRUE(RunExtensionTest("window_update/focus")) << message_;
    235   ASSERT_TRUE(::IsZoomed(window));
    236 }
    237 #endif  // OS_WIN
    238 
    239 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_UpdateWindowShowState) {
    240   ASSERT_TRUE(RunExtensionTest("window_update/show_state")) << message_;
    241 }
    242 
    243 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabledByPref) {
    244   IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(),
    245                                       IncognitoModePrefs::DISABLED);
    246 
    247   // This makes sure that creating an incognito window fails due to pref
    248   // (policy) being set.
    249   ASSERT_TRUE(RunExtensionTest("tabs/incognito_disabled")) << message_;
    250 }
    251 
    252 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_GetViewsOfCreatedPopup) {
    253   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_popup.html"))
    254       << message_;
    255 }
    256 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_GetViewsOfCreatedWindow) {
    257   ASSERT_TRUE(RunExtensionSubtest("tabs/basics", "get_views_window.html"))
    258       << message_;
    259 }
    260 
    261 // Adding a new test? Awesome. But API tests are the old hotness. The
    262 // new hotness is extension_test_utils. See tabs_test.cc for an example.
    263 // We are trying to phase out many uses of API tests as they tend to be flaky.
    264