1 // Copyright 2014 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 "base/files/file_path.h"
6 #include "base/strings/stringprintf.h"
7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/test/base/ui_test_utils.h"
9 #include "extensions/common/feature_switch.h"
10 #include "extensions/common/switches.h"
12 using extensions::Extension;
13 using extensions::FeatureSwitch;
15 class ExtensionOptionsApiTest : public ExtensionApiTest {
17 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
18 ExtensionApiTest::SetUpCommandLine(command_line);
20 enable_options_.reset(new FeatureSwitch::ScopedOverride(
21 FeatureSwitch::embedded_extension_options(), true));
22 // Need to add a command line flag as well as a FeatureSwitch because the
23 // FeatureSwitch is not copied over to the renderer process from the
25 command_line->AppendSwitch(
26 extensions::switches::kEnableEmbeddedExtensionOptions);
29 scoped_ptr<FeatureSwitch::ScopedOverride> enable_options_;
32 IN_PROC_BROWSER_TEST_F(ExtensionOptionsApiTest, ExtensionCanEmbedOwnOptions) {
33 base::FilePath extension_dir =
34 test_data_dir_.AppendASCII("extension_options").AppendASCII("embed_self");
35 ASSERT_TRUE(InstallExtension(extension_dir, 1));
36 ASSERT_TRUE(RunExtensionSubtest("extension_options/embed_self", "test.html"));
39 IN_PROC_BROWSER_TEST_F(ExtensionOptionsApiTest,
40 ShouldNotEmbedOtherExtensionsOptions) {
41 base::FilePath dir = test_data_dir_.AppendASCII("extension_options")
42 .AppendASCII("embed_other");
44 const Extension* embedder = InstallExtension(dir.AppendASCII("embedder"), 1);
45 const Extension* embedded = InstallExtension(dir.AppendASCII("embedded"), 1);
47 ASSERT_TRUE(embedder);
48 ASSERT_TRUE(embedded);
50 // Since the extension id of the embedded extension is not always the same,
51 // store the embedded extension id in the embedder's storage before running
53 std::string script = base::StringPrintf(
54 "chrome.storage.local.set({'embeddedId': '%s'}, function() {"
55 "window.domAutomationController.send('done injecting');});",
56 embedded->id().c_str());
58 ExecuteScriptInBackgroundPage(embedder->id(), script);
59 ResultCatcher catcher;
60 ui_test_utils::NavigateToURL(browser(),
61 embedder->GetResourceURL("test.html"));
62 ASSERT_TRUE(catcher.GetNextResult());
65 IN_PROC_BROWSER_TEST_F(ExtensionOptionsApiTest,
66 CannotEmbedUsingInvalidExtensionIds) {
67 ASSERT_TRUE(InstallExtension(test_data_dir_.AppendASCII("extension_options")
68 .AppendASCII("embed_invalid"),
71 RunExtensionSubtest("extension_options/embed_invalid", "test.html"));