Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / extension_action / extension_action_prefs_unittest.cc
blob6925b98e84c982218cfd7c7d81d168b82b77a084
1 // Copyright (c) 2013 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 <string>
7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
11 #include "chrome/browser/extensions/extension_prefs_unittest.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "extensions/common/extension.h"
15 namespace extensions {
17 // Tests force hiding browser actions.
18 class ExtensionPrefsHidingBrowserActions : public ExtensionPrefsTest {
19 public:
20 ExtensionPrefsHidingBrowserActions() {}
21 ~ExtensionPrefsHidingBrowserActions() override {}
23 void Initialize() override {
24 profile_.reset(new TestingProfile());
26 // Install 5 extensions.
27 for (int i = 0; i < 5; i++) {
28 std::string name = "test" + base::IntToString(i);
29 extensions_.push_back(prefs_.AddExtension(name));
32 ExtensionActionAPI* action_api = ExtensionActionAPI::Get(profile_.get());
33 action_api->set_prefs_for_testing(prefs());
34 for (const scoped_refptr<const Extension>& extension : extensions_)
35 EXPECT_TRUE(action_api->GetBrowserActionVisibility(extension->id()));
37 action_api->SetBrowserActionVisibility(extensions_[0]->id(), false);
38 action_api->SetBrowserActionVisibility(extensions_[1]->id(), true);
41 void Verify() override {
42 ExtensionActionAPI* action_api = ExtensionActionAPI::Get(profile_.get());
43 action_api->set_prefs_for_testing(prefs());
44 // Make sure the one we hid is hidden.
45 EXPECT_FALSE(action_api->GetBrowserActionVisibility(extensions_[0]->id()));
47 // Make sure the other id's are not hidden.
48 ExtensionList::const_iterator iter = extensions_.begin() + 1;
49 for (; iter != extensions_.end(); ++iter) {
50 SCOPED_TRACE(base::StringPrintf("Loop %d ",
51 static_cast<int>(iter - extensions_.begin())));
52 EXPECT_TRUE(action_api->GetBrowserActionVisibility((*iter)->id()));
56 private:
57 scoped_ptr<TestingProfile> profile_;
58 ExtensionList extensions_;
60 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefsHidingBrowserActions);
63 TEST_F(ExtensionPrefsHidingBrowserActions, ForceHide) {}
65 } // namespace extensions