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/extensions/extension_system.h"
8#include "chrome/browser/ui/browser.h"
9#include "chrome/browser/ui/tabs/tab_strip_model.h"
10#include "chrome/common/extensions/extension.h"
11#include "chrome/common/url_constants.h"
12#include "chrome/test/base/ui_test_utils.h"
13#include "content/public/browser/notification_service.h"
14#include "content/public/test/browser_test_utils.h"
15
16using extensions::Extension;
17
18// Used to simulate a click on the first element named 'Options'.
19static 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.
29IN_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  EXPECT_TRUE(content::ExecuteScriptInFrame(
48      tab_strip->GetActiveWebContents(),
49      "//iframe[starts-with(@src, 'chrome://extension')]",
50      kScriptClickOptionButton));
51  observer.Wait();
52  EXPECT_EQ(2, tab_strip->count());
53
54  EXPECT_EQ(extension->GetResourceURL("options.html"),
55            tab_strip->GetWebContentsAt(1)->GetURL());
56}
57