extension_install_ui_browsertest.cc revision 21d179b334e59e9a3bfcaed4c4430bef1bc5759d
1// Copyright (c) 2010 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/theme_installed_infobar_delegate.h"
8#include "chrome/browser/profiles/profile.h"
9#include "chrome/browser/tab_contents/tab_contents.h"
10#include "chrome/browser/ui/browser.h"
11#include "chrome/test/ui_test_utils.h"
12
13namespace {
14
15// Theme ID used for testing.
16const char* const theme_crx = "iamefpfkojoapidjnbafmgkgncegbkad";
17
18}  // namespace
19
20class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest {
21 public:
22  // Checks that a theme info bar is currently visible and issues an undo to
23  // revert to the previous theme.
24  void VerifyThemeInfoBarAndUndoInstall() {
25    TabContents* tab_contents = browser()->GetSelectedTabContents();
26    ASSERT_TRUE(tab_contents);
27    ASSERT_EQ(1, tab_contents->infobar_delegate_count());
28    ThemeInstalledInfoBarDelegate* delegate = tab_contents->
29        GetInfoBarDelegateAt(0)->AsThemePreviewInfobarDelegate();
30    ASSERT_TRUE(delegate);
31    delegate->Cancel();
32    ASSERT_EQ(0, tab_contents->infobar_delegate_count());
33  }
34};
35
36// Crashy, http://crbug.com/44548.
37IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest,
38                       DISABLED_TestThemeInstallUndoResetsToDefault) {
39  // Install theme once and undo to verify we go back to default theme.
40  FilePath theme_path = test_data_dir_.AppendASCII("theme.crx");
41  ASSERT_TRUE(InstallExtensionWithUI(theme_path, 1));
42  const Extension* theme = browser()->profile()->GetTheme();
43  ASSERT_TRUE(theme);
44  ASSERT_EQ(theme_crx, theme->id());
45  VerifyThemeInfoBarAndUndoInstall();
46  ASSERT_EQ(NULL, browser()->profile()->GetTheme());
47
48  // Set the same theme twice and undo to verify we go back to default theme.
49  // We set the |expected_change| to zero in these 'InstallExtensionWithUI'
50  // calls since the theme has already been installed above and this is an
51  // overinstall to set the active theme.
52  ASSERT_TRUE(InstallExtensionWithUI(theme_path, 0));
53  theme = browser()->profile()->GetTheme();
54  ASSERT_TRUE(theme);
55  ASSERT_EQ(theme_crx, theme->id());
56  ASSERT_TRUE(InstallExtensionWithUI(theme_path, 0));
57  theme = browser()->profile()->GetTheme();
58  ASSERT_TRUE(theme);
59  ASSERT_EQ(theme_crx, theme->id());
60  VerifyThemeInfoBarAndUndoInstall();
61  ASSERT_EQ(NULL, browser()->profile()->GetTheme());
62}
63