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_browsertest.h"
      6 #include "chrome/browser/extensions/extension_service.h"
      7 #include "chrome/browser/ui/browser.h"
      8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
      9 #include "chrome/common/url_constants.h"
     10 #include "chrome/test/base/ui_test_utils.h"
     11 #include "content/public/browser/notification_service.h"
     12 #include "content/public/test/browser_test_utils.h"
     13 #include "extensions/browser/extension_system.h"
     14 #include "extensions/common/extension.h"
     15 
     16 using extensions::Extension;
     17 
     18 // Used to simulate a click on the first element named 'Options'.
     19 static const char kScriptClickOptionButton[] =
     20     "(function() { "
     21     "  var button = document.querySelector('.options-link');"
     22     "  button.click();"
     23     "})();";
     24 
     25 // Test that an extension with an options page makes an 'Options' button appear
     26 // on chrome://extensions, and that clicking the button opens a new tab with the
     27 // extension's options page.
     28 // Disabled because of flakiness. See http://crbug.com/174934.
     29 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DISABLED_OptionsPage) {
     30   ExtensionService* service = extensions::ExtensionSystem::Get(
     31       browser()->profile())->extension_service();
     32   size_t installed_extensions = service->extensions()->size();
     33   // Install an extension with an options page.
     34   const Extension* extension =
     35       InstallExtension(test_data_dir_.AppendASCII("options.crx"), 1);
     36   ASSERT_TRUE(extension);
     37   EXPECT_EQ(installed_extensions + 1, service->extensions()->size());
     38 
     39   // Go to the Extension Settings page and click the Options button.
     40   ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIExtensionsURL));
     41   TabStripModel* tab_strip = browser()->tab_strip_model();
     42   ui_test_utils::WindowedTabAddedNotificationObserver observer(
     43       content::NotificationService::AllSources());
     44   // NOTE: Currently the above script needs to execute in an iframe. The
     45   // selector for that iframe may break if the layout of the extensions
     46   // page changes.
     47   content::RenderFrameHost* frame = content::FrameMatchingPredicate(
     48       tab_strip->GetActiveWebContents(),
     49       base::Bind(&content::FrameHasSourceUrl,
     50                  GURL(chrome::kChromeUIExtensionsFrameURL)));
     51   EXPECT_TRUE(content::ExecuteScript(
     52       frame,
     53       kScriptClickOptionButton));
     54   observer.Wait();
     55   EXPECT_EQ(2, tab_strip->count());
     56 
     57   EXPECT_EQ(extension->GetResourceURL("options.html"),
     58             tab_strip->GetWebContentsAt(1)->GetURL());
     59 }
     60