summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-20 14:37:09 +0000
committerbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-20 14:37:09 +0000
commitd7e5525dd72ef8fdd865d2ae0c8692f69b1856bf (patch)
treeab6f17a236cb5eca36a5bd7e146357962df78074
parentb699a178d982f7de0025e492e965c64b28c78026 (diff)
downloadchromium_src-d7e5525dd72ef8fdd865d2ae0c8692f69b1856bf.zip
chromium_src-d7e5525dd72ef8fdd865d2ae0c8692f69b1856bf.tar.gz
chromium_src-d7e5525dd72ef8fdd865d2ae0c8692f69b1856bf.tar.bz2
Close previous theme info bars when resetting to default theme
Select and close previous theme info bars when resetting to default theme via the options dialog. As a nice side effect if one tab is showing a theme info bar and the user switches to a different theme in another tab, this change closes the previous theme info bars as well. (landing for satish@chromium.org / http://codereview.chromium.org/1622017/show) BUG=35607 TEST=Install a theme, and with the theme info bar visible open Preferences dialog and click 'reset to default theme' and check the info bar. (full steps given in the above bug entry) Review URL: http://codereview.chromium.org/1650016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45034 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/automation_provider.cc11
-rw-r--r--chrome/browser/automation/automation_provider.h4
-rw-r--r--chrome/browser/extensions/theme_installed_infobar_delegate.cc35
-rw-r--r--chrome/browser/extensions/theme_installed_infobar_delegate.h19
-rw-r--r--chrome/test/automation/automation_messages_internal.h6
-rw-r--r--chrome/test/automation/automation_proxy.cc8
-rw-r--r--chrome/test/automation/automation_proxy.h11
-rw-r--r--chrome/test/automation/extension_proxy_uitest.cc4
-rw-r--r--chrome/test/interactive_ui/infobars_uitest.cc50
-rw-r--r--chrome/test/interactive_ui/interactive_ui_tests.gypi1
-rw-r--r--chrome/test/pyautolib/pyautolib.cc4
-rw-r--r--chrome/test/pyautolib/pyautolib.h2
-rw-r--r--chrome/test/pyautolib/pyautolib.i2
13 files changed, 138 insertions, 19 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index dadc49b..8fcdf03 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -567,6 +567,7 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForPopupMenuToOpen,
WaitForPopupMenuToOpen)
#endif
+ IPC_MESSAGE_HANDLER(AutomationMsg_ResetToDefaultTheme, ResetToDefaultTheme)
IPC_END_MESSAGE_MAP()
}
@@ -2823,7 +2824,7 @@ void AutomationProvider::WaitForExtensionTestResult(
}
void AutomationProvider::InstallExtensionAndGetHandle(
- const FilePath& crx_path, IPC::Message* reply_message) {
+ const FilePath& crx_path, bool with_ui, IPC::Message* reply_message) {
ExtensionsService* service = profile_->GetExtensionsService();
ExtensionProcessManager* manager = profile_->GetExtensionProcessManager();
if (service && manager) {
@@ -2834,10 +2835,12 @@ void AutomationProvider::InstallExtensionAndGetHandle(
AutomationMsg_InstallExtensionAndGetHandle::ID,
reply_message);
+ ExtensionInstallUI* client =
+ (with_ui ? new ExtensionInstallUI(profile_) : NULL);
scoped_refptr<CrxInstaller> installer(
new CrxInstaller(service->install_directory(),
service,
- NULL)); // silent install, no UI
+ client));
installer->set_allow_privilege_increase(true);
installer->InstallCrx(crx_path);
} else {
@@ -3037,3 +3040,7 @@ void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) {
NOTIMPLEMENTED();
}
#endif // !defined(TOOLKIT_VIEWS)
+
+void AutomationProvider::ResetToDefaultTheme() {
+ profile_->ClearTheme();
+}
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index 9c502ec..cb07f1c 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -402,6 +402,7 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
void WaitForExtensionTestResult(IPC::Message* reply_message);
void InstallExtensionAndGetHandle(const FilePath& crx_path,
+ bool with_ui,
IPC::Message* reply_message);
void UninstallExtension(int extension_handle,
@@ -565,6 +566,9 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
bool value,
bool* success);
+ // Resets to the default theme.
+ void ResetToDefaultTheme();
+
// Gets the current used encoding name of the page in the specified tab.
void GetPageCurrentEncoding(int tab_handle, std::string* current_encoding);
diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.cc b/chrome/browser/extensions/theme_installed_infobar_delegate.cc
index 196f9ff..345a57f 100644
--- a/chrome/browser/extensions/theme_installed_infobar_delegate.cc
+++ b/chrome/browser/extensions/theme_installed_infobar_delegate.cc
@@ -14,20 +14,28 @@
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/extensions/extension.h"
+#include "chrome/common/notification_service.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate(
TabContents* tab_contents, const Extension* new_theme,
const std::string& previous_theme_id)
- : ConfirmInfoBarDelegate(tab_contents),
- profile_(tab_contents->profile()),
- name_(new_theme->name()),
- previous_theme_id_(previous_theme_id) {
+ : ConfirmInfoBarDelegate(tab_contents),
+ profile_(tab_contents->profile()),
+ name_(new_theme->name()),
+ theme_id_(new_theme->id()),
+ previous_theme_id_(previous_theme_id),
+ tab_contents_(tab_contents) {
profile_->GetThemeProvider()->OnInfobarDisplayed();
+ registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
+ NotificationService::AllSources());
}
ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() {
+ // We don't want any notifications while we're running our destructor.
+ registrar_.RemoveAll();
+
profile_->GetThemeProvider()->OnInfobarDestroyed();
}
@@ -85,3 +93,22 @@ bool ThemeInstalledInfoBarDelegate::Cancel() {
profile_->ClearTheme();
return true;
}
+
+void ThemeInstalledInfoBarDelegate::Observe(
+ NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ switch (type.value) {
+ case NotificationType::BROWSER_THEME_CHANGED: {
+ // If the new theme is different from what this info bar is associated
+ // with, close this info bar since it is no longer relevant.
+ Extension* extension = Details<Extension>(details).ptr();
+ if (!extension || theme_id_ != extension->id())
+ tab_contents_->RemoveInfoBar(this);
+ break;
+ }
+
+ default:
+ NOTREACHED();
+ }
+}
diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.h b/chrome/browser/extensions/theme_installed_infobar_delegate.h
index b8baf41..beb99c6 100644
--- a/chrome/browser/extensions/theme_installed_infobar_delegate.h
+++ b/chrome/browser/extensions/theme_installed_infobar_delegate.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_EXTENSIONS_THEME_INSTALLED_INFOBAR_DELEGATE_H_
#include "chrome/browser/tab_contents/infobar_delegate.h"
+#include "chrome/common/notification_registrar.h"
class Extension;
class SkBitmap;
@@ -13,7 +14,8 @@ class TabContents;
// When a user installs a theme, we display it immediately, but provide an
// infobar allowing them to cancel.
-class ThemeInstalledInfoBarDelegate : public ConfirmInfoBarDelegate {
+class ThemeInstalledInfoBarDelegate : public ConfirmInfoBarDelegate,
+ public NotificationObserver {
public:
ThemeInstalledInfoBarDelegate(TabContents* tab_contents,
const Extension* new_theme,
@@ -28,15 +30,30 @@ class ThemeInstalledInfoBarDelegate : public ConfirmInfoBarDelegate {
ConfirmInfoBarDelegate::InfoBarButton button) const;
virtual bool Cancel();
+ // NotificationObserver implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
protected:
Profile* profile() { return profile_; }
private:
Profile* profile_;
+
// Name of theme that's just been installed.
std::string name_;
+
+ // ID of theme that's just been installed.
+ std::string theme_id_;
+
// Used to undo theme install.
std::string previous_theme_id_;
+
+ // Tab to which this info bar is associated.
+ TabContents* tab_contents_;
+
+ // Registers and unregisters us for notifications.
+ NotificationRegistrar registrar_;
};
#endif // CHROME_BROWSER_EXTENSIONS_THEME_INSTALLED_INFOBAR_DELEGATE_H_
diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h
index d938b9f..02ee3e4 100644
--- a/chrome/test/automation/automation_messages_internal.h
+++ b/chrome/test/automation/automation_messages_internal.h
@@ -1327,8 +1327,9 @@ IPC_BEGIN_MESSAGES(Automation)
// Installs an extension from the crx file and returns its id.
// On error, |extension handle| will be 0.
- IPC_SYNC_MESSAGE_ROUTED1_1(AutomationMsg_InstallExtensionAndGetHandle,
+ IPC_SYNC_MESSAGE_ROUTED2_1(AutomationMsg_InstallExtensionAndGetHandle,
FilePath /* full path to crx file */,
+ bool /* with UI */,
int /* extension handle */)
// Waits for the next extension test result. Sets |test result| as the
@@ -1377,4 +1378,7 @@ IPC_BEGIN_MESSAGES(Automation)
bool /* success */,
std::string /* property value */)
+ // Resets to the default theme.
+ IPC_SYNC_MESSAGE_ROUTED0_0(AutomationMsg_ResetToDefaultTheme)
+
IPC_END_MESSAGES(Automation)
diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc
index ecaf5d8..d49ae9a 100644
--- a/chrome/test/automation/automation_proxy.cc
+++ b/chrome/test/automation/automation_proxy.cc
@@ -234,9 +234,9 @@ bool AutomationProxy::SavePackageShouldPromptUser(bool should_prompt) {
}
scoped_refptr<ExtensionProxy> AutomationProxy::InstallExtension(
- const FilePath& crx_file) {
+ const FilePath& crx_file, bool with_ui) {
int handle = 0;
- if (!Send(new AutomationMsg_InstallExtensionAndGetHandle(0, crx_file,
+ if (!Send(new AutomationMsg_InstallExtensionAndGetHandle(0, crx_file, with_ui,
&handle)))
return NULL;
@@ -531,3 +531,7 @@ bool AutomationProxy::LoginWithUserAndPass(const std::string& username,
return sent && success;
}
#endif
+
+bool AutomationProxy::ResetToDefaultTheme() {
+ return Send(new AutomationMsg_ResetToDefaultTheme(0));
+}
diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h
index f68633e..45286fe 100644
--- a/chrome/test/automation/automation_proxy.h
+++ b/chrome/test/automation/automation_proxy.h
@@ -183,10 +183,12 @@ class AutomationProxy : public IPC::Channel::Listener,
// sent.
bool SavePackageShouldPromptUser(bool should_prompt) WARN_UNUSED_RESULT;
- // Installs the extension crx. Returns the ExtensionProxy for the
- // installed extension, or NULL on failure.
+ // Installs the extension crx. If |with_ui| is true an install confirmation
+ // and notification UI is shown, otherwise the install is silent. Returns the
+ // ExtensionProxy for the installed extension, or NULL on failure.
// Note: Overinstalls and downgrades will return NULL.
- scoped_refptr<ExtensionProxy> InstallExtension(const FilePath& crx_file);
+ scoped_refptr<ExtensionProxy> InstallExtension(const FilePath& crx_file,
+ bool with_ui);
// Asserts that the next extension test result is true.
void EnsureExtensionTestResult();
@@ -195,6 +197,9 @@ class AutomationProxy : public IPC::Channel::Listener,
// Returns true on success.
bool GetEnabledExtensions(std::vector<FilePath>* extension_directories);
+ // Resets to the default theme. Returns true on success.
+ bool ResetToDefaultTheme();
+
#if defined(OS_CHROMEOS)
// Logs in through the Chrome OS login wizard with given |username|
// and |password|. Returns true on success.
diff --git a/chrome/test/automation/extension_proxy_uitest.cc b/chrome/test/automation/extension_proxy_uitest.cc
index 18d385c..0954f5a 100644
--- a/chrome/test/automation/extension_proxy_uitest.cc
+++ b/chrome/test/automation/extension_proxy_uitest.cc
@@ -32,7 +32,7 @@ class ExtensionProxyUITest : public UITest {
scoped_refptr<ExtensionProxy> InstallSimpleBrowserActionExtension() {
return automation()->InstallExtension(
test_data_directory_.AppendASCII("extensions").AppendASCII("uitest").
- AppendASCII("simple_browser_action.crx"));
+ AppendASCII("simple_browser_action.crx"), false);
}
// Installs a extension which, when clicking the browser action, renames
@@ -41,7 +41,7 @@ class ExtensionProxyUITest : public UITest {
scoped_refptr<ExtensionProxy> InstallRenameTabExtension() {
return automation()->InstallExtension(
test_data_directory_.AppendASCII("extensions").AppendASCII("uitest").
- AppendASCII("rename_tab.crx"));
+ AppendASCII("rename_tab.crx"), false);
}
// The google translate extension, which is installed on test setup.
diff --git a/chrome/test/interactive_ui/infobars_uitest.cc b/chrome/test/interactive_ui/infobars_uitest.cc
new file mode 100644
index 0000000..4670ad6
--- /dev/null
+++ b/chrome/test/interactive_ui/infobars_uitest.cc
@@ -0,0 +1,50 @@
+// Copyright (c) 2010 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/test/automation/browser_proxy.h"
+#include "chrome/test/automation/extension_proxy.h"
+#include "chrome/test/automation/tab_proxy.h"
+#include "chrome/test/ui/ui_test.h"
+#include "net/url_request/url_request_unittest.h"
+
+class InfoBarsUITest : public UITest {
+ public:
+ InfoBarsUITest() {
+ show_window_ = true;
+ }
+};
+
+TEST_F(InfoBarsUITest, TestInfoBarsCloseOnNewTheme) {
+ const wchar_t kDocRoot[] = L"chrome/test/data";
+ scoped_refptr<HTTPTestServer> server =
+ HTTPTestServer::CreateServer(kDocRoot, NULL);
+ ASSERT_TRUE(server.get() != NULL);
+ scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
+ ASSERT_TRUE(browser.get());
+
+ scoped_refptr<TabProxy> tab_1(browser->GetActiveTab());
+ ASSERT_TRUE(tab_1.get());
+ EXPECT_TRUE(tab_1->NavigateToURL(
+ server->TestServerPageW(L"files/simple.html")));
+ scoped_refptr<ExtensionProxy> theme = automation()->InstallExtension(
+ test_data_directory_.AppendASCII("extensions").AppendASCII("theme.crx"),
+ true);
+ ASSERT_TRUE(theme != NULL);
+ EXPECT_TRUE(tab_1->WaitForInfoBarCount(1, action_max_timeout_ms()));
+
+ EXPECT_TRUE(browser->AppendTab(
+ server->TestServerPageW(L"files/simple.html")));
+ WaitUntilTabCount(2);
+ scoped_refptr<TabProxy> tab_2(browser->GetActiveTab());
+ ASSERT_TRUE(tab_2.get());
+ theme = automation()->InstallExtension(
+ test_data_directory_.AppendASCII("extensions").AppendASCII("theme2.crx"),
+ true);
+ ASSERT_TRUE(theme != NULL);
+ EXPECT_TRUE(tab_2->WaitForInfoBarCount(1, action_max_timeout_ms()));
+ EXPECT_TRUE(tab_1->WaitForInfoBarCount(0, action_max_timeout_ms()));
+
+ EXPECT_TRUE(automation()->ResetToDefaultTheme());
+ EXPECT_TRUE(tab_2->WaitForInfoBarCount(0, action_max_timeout_ms()));
+}
diff --git a/chrome/test/interactive_ui/interactive_ui_tests.gypi b/chrome/test/interactive_ui/interactive_ui_tests.gypi
index 603b7fa..880dfb3 100644
--- a/chrome/test/interactive_ui/interactive_ui_tests.gypi
+++ b/chrome/test/interactive_ui/interactive_ui_tests.gypi
@@ -38,6 +38,7 @@
'<(DEPTH)/chrome/browser/views/tabs/tab_dragging_test.cc',
'<(DEPTH)/chrome/test/in_process_browser_test.cc',
'<(DEPTH)/chrome/test/in_process_browser_test.h',
+ '<(DEPTH)/chrome/test/interactive_ui/infobars_uitest.cc',
'<(DEPTH)/chrome/test/interactive_ui/keyboard_access_uitest.cc',
'<(DEPTH)/chrome/test/interactive_ui/npapi_interactive_test.cc',
'<(DEPTH)/chrome/test/interactive_ui/view_event_test_base.cc',
diff --git a/chrome/test/pyautolib/pyautolib.cc b/chrome/test/pyautolib/pyautolib.cc
index 39a5b32..fab3832 100644
--- a/chrome/test/pyautolib/pyautolib.cc
+++ b/chrome/test/pyautolib/pyautolib.cc
@@ -156,9 +156,9 @@ bool PyUITestBase::OpenNewBrowserWindow(bool show) {
return automation()->OpenNewBrowserWindow(Browser::TYPE_NORMAL, show);
}
-bool PyUITestBase::InstallExtension(const FilePath& crx_file) {
+bool PyUITestBase::InstallExtension(const FilePath& crx_file, bool with_ui) {
scoped_refptr<ExtensionProxy> proxy =
- automation()->InstallExtension(crx_file);
+ automation()->InstallExtension(crx_file, with_ui);
return proxy.get() != NULL;
}
diff --git a/chrome/test/pyautolib/pyautolib.h b/chrome/test/pyautolib/pyautolib.h
index 1093fda..321cfde 100644
--- a/chrome/test/pyautolib/pyautolib.h
+++ b/chrome/test/pyautolib/pyautolib.h
@@ -100,7 +100,7 @@ class PyUITestBase : public UITestBase {
// Installs the extension crx. Returns true only if extension was installed
// and loaded successfully. Overinstalls will fail.
- bool InstallExtension(const FilePath& crx_file);
+ bool InstallExtension(const FilePath& crx_file, bool with_ui);
// Returns bookmark bar visibility state.
bool GetBookmarkBarVisibility();
diff --git a/chrome/test/pyautolib/pyautolib.i b/chrome/test/pyautolib/pyautolib.i
index 3fdddc4..e974319 100644
--- a/chrome/test/pyautolib/pyautolib.i
+++ b/chrome/test/pyautolib/pyautolib.i
@@ -312,7 +312,7 @@ class PyUITestBase {
%feature("docstring", "Install an extension from the given file. Returns "
"True if successfully installed and loaded.") InstallExtension;
- bool InstallExtension(const FilePath& crx_file);
+ bool InstallExtension(const FilePath& crx_file, bool with_ui);
%feature("docstring", "Get a proxy to the browser window at the given "
"zero-based index.") GetBrowserWindow;