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

Side by Side Diff: chrome/browser/ui/toolbar/browser_actions_bar_browsertest.cc

Issue 640423003: Create a cross-platform browsertest for the browser actions bar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/ui/toolbar/browser_actions_bar_browsertest.h"
6
7 #include "chrome/browser/extensions/browser_action_test_util.h"
8 #include "chrome/browser/extensions/extension_browsertest.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "components/crx_file/id_util.h"
11 #include "extensions/browser/extension_registry.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/extension_builder.h"
14 #include "extensions/common/value_builder.h"
15
16 using extensions::Extension;
Peter Kasting 2014/10/10 20:32:51 Nit: Avoid using directives unless they significan
Devlin 2014/10/10 20:40:23 Whoops, sorry. Copy and paste from other file tha
17
18 namespace {
19
20 scoped_refptr<const Extension> CreateExtension(const std::string& name,
21 bool has_browser_action) {
22 extensions::DictionaryBuilder manifest;
23 manifest.Set("name", name).
24 Set("description", "an extension").
25 Set("manifest_version", 2).
26 Set("version", "1.0");
27 if (has_browser_action)
28 manifest.Set("browser_action", extensions::DictionaryBuilder().Pass());
29 return extensions::ExtensionBuilder().
30 SetManifest(manifest.Pass()).
31 SetID(crx_file::id_util::GenerateId(name)).
32 Build();
33 }
34
35 } // namespace
36
37 BrowserActionsBarBrowserTest::BrowserActionsBarBrowserTest() {
38 }
39
40 BrowserActionsBarBrowserTest::~BrowserActionsBarBrowserTest() {
41 }
42
43 void BrowserActionsBarBrowserTest::SetUpCommandLine(
44 base::CommandLine* command_line) {
45 BrowserActionTestUtil::DisableAnimations();
46 ExtensionBrowserTest::SetUpCommandLine(command_line);
47 }
48
49 void BrowserActionsBarBrowserTest::SetUpOnMainThread() {
50 ExtensionBrowserTest::SetUpOnMainThread();
51 browser_actions_bar_.reset(new BrowserActionTestUtil(browser()));
52 }
53
54 void BrowserActionsBarBrowserTest::TearDownOnMainThread() {
55 BrowserActionTestUtil::EnableAnimations();
56 ExtensionBrowserTest::TearDownOnMainThread();
57 }
58
59 void BrowserActionsBarBrowserTest::LoadExtensions() {
60 // Create three extensions with browser actions.
61 extension_a_ = CreateExtension("alpha", true);
62 extension_b_ = CreateExtension("beta", true);
63 extension_c_ = CreateExtension("gamma", true);
64
65 const Extension* extensions[] =
66 { extension_a(), extension_b(), extension_c() };
67 extensions::ExtensionRegistry* registry =
68 extensions::ExtensionRegistry::Get(profile());
69 // Add each, and verify that it is both correctly added to the extension
70 // registry and to the browser actions container.
71 for (size_t i = 0; i < arraysize(extensions); ++i) {
72 extension_service()->AddExtension(extensions[i]);
73 EXPECT_TRUE(registry->enabled_extensions().GetByID(extensions[i]->id())) <<
74 extensions[i]->name();
75 EXPECT_EQ(static_cast<int>(i + 1),
76 browser_actions_bar_->NumberOfBrowserActions());
77 EXPECT_TRUE(browser_actions_bar_->HasIcon(i));
78 EXPECT_EQ(static_cast<int>(i + 1),
79 browser_actions_bar()->VisibleBrowserActions());
80 }
81 }
82
83 // Test the basic functionality.
84 IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest, Basic) {
85 // Load an extension with no browser action.
86 extension_service()->AddExtension(CreateExtension("alpha", false).get());
87 // This extension should not be in the model (has no browser action).
88 EXPECT_EQ(0, browser_actions_bar()->NumberOfBrowserActions());
89
90 // Load an extension with a browser action.
91 extension_service()->AddExtension(CreateExtension("beta", true).get());
92 EXPECT_EQ(1, browser_actions_bar()->NumberOfBrowserActions());
93 EXPECT_TRUE(browser_actions_bar()->HasIcon(0));
94
95 // Unload the extension.
96 std::string id = browser_actions_bar()->GetExtensionId(0);
97 UnloadExtension(id);
98 EXPECT_EQ(0, browser_actions_bar()->NumberOfBrowserActions());
99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698