Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3905)

Unified Diff: chrome/browser/extensions/extension_management_api_browsertest.cc

Issue 6546072: Clean up how we handle themes in the extensions system and management API.... Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_management_api_browsertest.cc
===================================================================
--- chrome/browser/extensions/extension_management_api_browsertest.cc (revision 75613)
+++ chrome/browser/extensions/extension_management_api_browsertest.cc (working copy)
@@ -1,19 +1,57 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/extensions/extension_browsertest.h"
+#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
-class ExtensionManagementApiBrowserTest : public ExtensionBrowserTest {};
+class ExtensionManagementApiBrowserTest : public ExtensionBrowserTest {
+ public:
+ // Loads the extension at "test_data_dir_/|path_suffix|" and waits for it to
+ // call chrome.test.sendMessge("ready") indicating that it's ready for the
+ // test to proceed.
+ void LoadExtensionAndWaitForReady(const char* path_suffix) {
+ ExtensionTestMessageListener ready("ready", false);
+ ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(path_suffix)));
+ ASSERT_TRUE(ready.WaitUntilSatisfied());
+ }
+ void InstallThemeAndWait(const char* path_suffix,
+ bool is_update, /* is this an update of a theme? */
+ const char* wait_message) {
+ ExtensionTestMessageListener listener(wait_message, false);
+ ASSERT_TRUE(InstallExtensionWithUI(test_data_dir_.AppendASCII(path_suffix),
+ is_update ? 0 : 1));
+ ASSERT_TRUE(listener.WaitUntilSatisfied());
+ }
+
+
+ void LoadExtensionWithTest(const char* extension_path,
+ const char* js_file) {
+ ExtensionTestMessageListener bootstrap("bootstrap", true);
+ ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(extension_path)));
+ ASSERT_TRUE(bootstrap.WaitUntilSatisfied());
+
+ ExtensionTestMessageListener ready("ready", false);
+ bootstrap.Reply(std::string(js_file));
+ ASSERT_TRUE(ready.WaitUntilSatisfied());
+ }
+
+ void InstallTwoThemes() {
+ ASSERT_TRUE(InstallExtensionWithUI(test_data_dir_.AppendASCII("theme.crx"),
+ 1));
+ ASSERT_TRUE(InstallExtensionWithUI(test_data_dir_.AppendASCII("theme2.crx"),
+ 0));
+ }
+};
+
// We test this here instead of in an ExtensionApiTest because normal extensions
// are not allowed to call the install function.
IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, InstallEvent) {
- ExtensionTestMessageListener listener1("ready", false);
- ASSERT_TRUE(LoadExtension(
- test_data_dir_.AppendASCII("management/install_event")));
- ASSERT_TRUE(listener1.WaitUntilSatisfied());
+ LoadExtensionAndWaitForReady("management/install_event");
ExtensionTestMessageListener listener2("got_event", false);
ASSERT_TRUE(LoadExtension(
@@ -43,3 +81,150 @@
test_data_dir_.AppendASCII("management/launch_app_from_background")));
ASSERT_TRUE(listener1.WaitUntilSatisfied());
}
+
+IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, ThemeBasics) {
+ LoadExtensionWithTest("management/themes", "basics.js");
+
+ // Install one theme - we should send events for install and enable.
+ InstallThemeAndWait("theme.crx", false, "step1");
+
+ ExtensionTestMessageListener step3("step3", true);
+ ExtensionTestMessageListener step4("step4", true);
+
+ // Install a second theme - we should send install/enable events for the
+ // first theme and a disable event for the second one.
+ InstallThemeAndWait("theme2.crx", true, "step2");
+
+ // Now tell the extension to go ahead and disable theme2.
+ ASSERT_TRUE(step3.WaitUntilSatisfied());
+ step3.Reply("step3_ack");
+ ASSERT_TRUE(step4.WaitUntilSatisfied());
+
+ // Make sure the theme is no longer enabled.
+ ExtensionService* service = browser()->profile()->GetExtensionService();
+ std::string id("pjpgmfcmabopnnfonnhmdjglfpjjfkbf");
+ ASSERT_EQ(NULL, service->GetExtensionById(id, false));
+ ASSERT_TRUE(service->GetExtensionById(id, true) != NULL);
+ ASSERT_EQ(NULL, browser()->profile()->GetTheme());
+}
+
+// Install theme1, then undo.
+IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, ThemeUndo1) {
+ LoadExtensionWithTest("management/themes", "undo.js");
+
+ InstallThemeAndWait("theme.crx", false, "step1");
+
+ ExtensionTestMessageListener step2("step2", false);
+ VerifyThemeInfoBarAndUndoInstall();
+ ASSERT_TRUE(step2.WaitUntilSatisfied());
+}
+
+// Install theme1, then install theme2, then undo.
+IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, ThemeUndo2) {
+ ASSERT_TRUE(InstallExtensionWithUI(test_data_dir_.AppendASCII("theme.crx"),
+ 1));
+ ASSERT_TRUE(InstallExtensionWithUI(test_data_dir_.AppendASCII("theme2.crx"),
+ 0));
+
+ LoadExtensionWithTest("management/themes", "undo2.js");
+
+ ExtensionTestMessageListener step1("step1", false);
+ VerifyThemeInfoBarAndUndoInstall();
+ ASSERT_TRUE(step1.WaitUntilSatisfied());
+}
+
+
+// Test "clear theme" functionality.
+IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, ClearTheme) {
+ LoadExtensionWithTest("management/themes", "clear_theme.js");
+
+ InstallThemeAndWait("theme.crx", false, "step1");
+
+ ExtensionTestMessageListener step2("step2", false);
+ browser()->profile()->ClearTheme();
+ ASSERT_TRUE(step2.WaitUntilSatisfied());
+}
+
+// Install theme1, then uninstall theme1.
+IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, UninstallTheme) {
+ ASSERT_TRUE(InstallExtensionWithUI(test_data_dir_.AppendASCII("theme.crx"),
+ 1));
+ ExtensionService* service = browser()->profile()->GetExtensionService();
+ std::string id("iamefpfkojoapidjnbafmgkgncegbkad");
+
+ ASSERT_TRUE(service->GetExtensionById(id, false) != NULL);
+ const Extension* theme = browser()->profile()->GetTheme();
+ ASSERT_TRUE(theme != NULL);
+ ASSERT_EQ(id, theme->id());
+
+ LoadExtensionWithTest("management/themes", "uninstall.js");
+
+ theme = browser()->profile()->GetTheme();
+ ASSERT_EQ(NULL, theme);
+}
+
+// Install theme1, then install theme2, then enable theme1.
+IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, EnableDisabledTheme) {
+ ASSERT_TRUE(InstallExtensionWithUI(test_data_dir_.AppendASCII("theme.crx"),
+ 1));
+ ASSERT_TRUE(InstallExtensionWithUI(test_data_dir_.AppendASCII("theme2.crx"),
+ 0));
+ ExtensionTestMessageListener step1("step1", false);
+ LoadExtensionWithTest("management/themes", "enable_disabled.js");
+ ASSERT_TRUE(step1.WaitUntilSatisfied());
+
+ std::string id("iamefpfkojoapidjnbafmgkgncegbkad");
+ const Extension* theme = browser()->profile()->GetTheme();
+ ASSERT_TRUE(theme != NULL);
+ ASSERT_EQ(id, theme->id());
+}
+
+// Install theme1, install theme2, disable theme2, enable theme1.
+IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest, ThemeEnabling) {
+ InstallTwoThemes();
+ ExtensionTestMessageListener step1("step1", true);
+ ExtensionTestMessageListener step2("step2", false);
+
+ LoadExtensionWithTest("management/themes", "enabling.js");
+ ASSERT_TRUE(step1.WaitUntilSatisfied());
+
+ const Extension* theme = browser()->profile()->GetTheme();
+ ASSERT_EQ(NULL, theme);
+
+ step1.Reply("step1_ack");
+ ASSERT_TRUE(step2.WaitUntilSatisfied());
+
+ std::string id("iamefpfkojoapidjnbafmgkgncegbkad");
+ theme = browser()->profile()->GetTheme();
+ ASSERT_TRUE(theme != NULL);
+ ASSERT_EQ(id, theme->id());
+}
+
+// Install theme1, install theme2, uninstall theme2.
+IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest,
+ UninstallEnabledTheme) {
+ InstallTwoThemes();
+ ExtensionTestMessageListener step1("step1", true);
+ ExtensionTestMessageListener step2("step2", false);
+ LoadExtensionWithTest("management/themes", "uninstall_enabled.js");
+ ASSERT_TRUE(step1.WaitUntilSatisfied());
+
+ const Extension* theme = browser()->profile()->GetTheme();
+ ASSERT_EQ(NULL, theme);
+}
+
+// Install theme1, disable, enable.
+IN_PROC_BROWSER_TEST_F(ExtensionManagementApiBrowserTest,
+ DisableThenEnableTheme) {
+ ASSERT_TRUE(InstallExtensionWithUI(test_data_dir_.AppendASCII("theme.crx"),
+ 1));
+
+ ExtensionTestMessageListener step1("step1", false);
+ LoadExtensionWithTest("management/themes", "disable_then_enable.js");
+ ASSERT_TRUE(step1.WaitUntilSatisfied());
+
+ std::string id("iamefpfkojoapidjnbafmgkgncegbkad");
+ const Extension* theme = browser()->profile()->GetTheme();
+ ASSERT_TRUE(theme != NULL);
+ ASSERT_EQ(id, theme->id());
+}
« no previous file with comments | « chrome/browser/extensions/extension_management_api.cc ('k') | chrome/browser/extensions/extension_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698