OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/extension_action_manager.h" | 5 #include "chrome/browser/extensions/extension_action_manager.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "chrome/browser/extensions/extension_action.h" | 8 #include "chrome/browser/extensions/extension_action.h" |
9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
10 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 class ExtensionActionManagerTest : public testing::Test { | 26 class ExtensionActionManagerTest : public testing::Test { |
27 public: | 27 public: |
28 ExtensionActionManagerTest(); | 28 ExtensionActionManagerTest(); |
29 | 29 |
30 protected: | 30 protected: |
31 // Build an extension, populating |action_type| key with |action|, and | 31 // Build an extension, populating |action_type| key with |action|, and |
32 // "icons" key with |extension_icons|. | 32 // "icons" key with |extension_icons|. |
33 scoped_refptr<Extension> BuildExtension( | 33 scoped_refptr<Extension> BuildExtension( |
34 scoped_ptr<base::DictionaryValue> extension_icons, | 34 std::unique_ptr<base::DictionaryValue> extension_icons, |
35 scoped_ptr<base::DictionaryValue> action, | 35 std::unique_ptr<base::DictionaryValue> action, |
36 const char* action_type); | 36 const char* action_type); |
37 | 37 |
38 // Returns true if |action|'s title matches |extension|'s name. | 38 // Returns true if |action|'s title matches |extension|'s name. |
39 bool TitlesMatch(const Extension& extension, const ExtensionAction& action); | 39 bool TitlesMatch(const Extension& extension, const ExtensionAction& action); |
40 | 40 |
41 // Returns true if |action|'s icon for size |action_key| matches | 41 // Returns true if |action|'s icon for size |action_key| matches |
42 // |extension|'s icon for size |extension_key|; | 42 // |extension|'s icon for size |extension_key|; |
43 bool IconsMatch(const Extension& extension, | 43 bool IconsMatch(const Extension& extension, |
44 int extension_key, | 44 int extension_key, |
45 const ExtensionAction& action, | 45 const ExtensionAction& action, |
46 int action_key); | 46 int action_key); |
47 | 47 |
48 // Returns the appropriate action for |extension| according to |action_type|. | 48 // Returns the appropriate action for |extension| according to |action_type|. |
49 ExtensionAction* GetAction(const char* action_type, | 49 ExtensionAction* GetAction(const char* action_type, |
50 const Extension& extension); | 50 const Extension& extension); |
51 | 51 |
52 // Tests that values that are missing from the |action_type| key are properly | 52 // Tests that values that are missing from the |action_type| key are properly |
53 // populated with values from the other keys in the manifest (e.g. | 53 // populated with values from the other keys in the manifest (e.g. |
54 // "default_icon" key of |action_type| is populated with "icons" key). | 54 // "default_icon" key of |action_type| is populated with "icons" key). |
55 void TestPopulateMissingValues(const char* action_type); | 55 void TestPopulateMissingValues(const char* action_type); |
56 | 56 |
57 ExtensionActionManager* manager() { return manager_; } | 57 ExtensionActionManager* manager() { return manager_; } |
58 | 58 |
59 private: | 59 private: |
60 content::TestBrowserThreadBundle thread_bundle_; | 60 content::TestBrowserThreadBundle thread_bundle_; |
61 ExtensionRegistry* registry_; | 61 ExtensionRegistry* registry_; |
62 int curr_id_; | 62 int curr_id_; |
63 ExtensionActionManager* manager_; | 63 ExtensionActionManager* manager_; |
64 scoped_ptr<TestingProfile> profile_; | 64 std::unique_ptr<TestingProfile> profile_; |
65 }; | 65 }; |
66 | 66 |
67 ExtensionActionManagerTest::ExtensionActionManagerTest() | 67 ExtensionActionManagerTest::ExtensionActionManagerTest() |
68 : curr_id_(0), | 68 : curr_id_(0), |
69 profile_(new TestingProfile) { | 69 profile_(new TestingProfile) { |
70 registry_ = ExtensionRegistry::Get(profile_.get()); | 70 registry_ = ExtensionRegistry::Get(profile_.get()); |
71 manager_ = ExtensionActionManager::Get(profile_.get()); | 71 manager_ = ExtensionActionManager::Get(profile_.get()); |
72 } | 72 } |
73 | 73 |
74 scoped_refptr<Extension> ExtensionActionManagerTest::BuildExtension( | 74 scoped_refptr<Extension> ExtensionActionManagerTest::BuildExtension( |
75 scoped_ptr<base::DictionaryValue> extension_icons, | 75 std::unique_ptr<base::DictionaryValue> extension_icons, |
76 scoped_ptr<base::DictionaryValue> action, | 76 std::unique_ptr<base::DictionaryValue> action, |
77 const char* action_type) { | 77 const char* action_type) { |
78 std::string id = base::IntToString(curr_id_++); | 78 std::string id = base::IntToString(curr_id_++); |
79 scoped_refptr<Extension> extension = | 79 scoped_refptr<Extension> extension = |
80 ExtensionBuilder() | 80 ExtensionBuilder() |
81 .SetManifest( | 81 .SetManifest( |
82 DictionaryBuilder() | 82 DictionaryBuilder() |
83 .Set("version", "1") | 83 .Set("version", "1") |
84 .Set("manifest_version", 2) | 84 .Set("manifest_version", 2) |
85 .Set("icons", std::move(extension_icons)) | 85 .Set("icons", std::move(extension_icons)) |
86 .Set(action_type, std::move(action)) | 86 .Set(action_type, std::move(action)) |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 DictionaryBuilder().Set("48", "icon48.png").Build(), | 200 DictionaryBuilder().Set("48", "icon48.png").Build(), |
201 DictionaryBuilder() | 201 DictionaryBuilder() |
202 .Set("default_title", "Action!") | 202 .Set("default_title", "Action!") |
203 .Set("default_icon", | 203 .Set("default_icon", |
204 DictionaryBuilder().Set("38", "action38.png").Build()) | 204 DictionaryBuilder().Set("38", "action38.png").Build()) |
205 .Build(), | 205 .Build(), |
206 kPageAction); | 206 kPageAction); |
207 ASSERT_TRUE(extension.get()); | 207 ASSERT_TRUE(extension.get()); |
208 | 208 |
209 // Get a "best fit" browser action for |extension|. | 209 // Get a "best fit" browser action for |extension|. |
210 scoped_ptr<ExtensionAction> action = | 210 std::unique_ptr<ExtensionAction> action = |
211 manager()->GetBestFitAction(*extension.get(), ActionInfo::TYPE_BROWSER); | 211 manager()->GetBestFitAction(*extension.get(), ActionInfo::TYPE_BROWSER); |
212 ASSERT_TRUE(action.get()); | 212 ASSERT_TRUE(action.get()); |
213 ASSERT_EQ(action->action_type(), ActionInfo::TYPE_BROWSER); | 213 ASSERT_EQ(action->action_type(), ActionInfo::TYPE_BROWSER); |
214 | 214 |
215 // |action|'s title and default icon should match |extension|'s page action's. | 215 // |action|'s title and default icon should match |extension|'s page action's. |
216 ASSERT_EQ(action->GetTitle(ExtensionAction::kDefaultTabId), "Action!"); | 216 ASSERT_EQ(action->GetTitle(ExtensionAction::kDefaultTabId), "Action!"); |
217 ASSERT_EQ(action->default_icon()->Get(38, ExtensionIconSet::MATCH_EXACTLY), | 217 ASSERT_EQ(action->default_icon()->Get(38, ExtensionIconSet::MATCH_EXACTLY), |
218 "action38.png"); | 218 "action38.png"); |
219 | 219 |
220 // Create a new extension without page action defaults. | 220 // Create a new extension without page action defaults. |
221 extension = | 221 extension = |
222 BuildExtension(DictionaryBuilder().Set("48", "icon48.png").Build(), | 222 BuildExtension(DictionaryBuilder().Set("48", "icon48.png").Build(), |
223 DictionaryBuilder().Build(), kPageAction); | 223 DictionaryBuilder().Build(), kPageAction); |
224 ASSERT_TRUE(extension.get()); | 224 ASSERT_TRUE(extension.get()); |
225 | 225 |
226 action = | 226 action = |
227 manager()->GetBestFitAction(*extension.get(), ActionInfo::TYPE_BROWSER); | 227 manager()->GetBestFitAction(*extension.get(), ActionInfo::TYPE_BROWSER); |
228 | 228 |
229 // Now these values match because |extension| does not have page action | 229 // Now these values match because |extension| does not have page action |
230 // defaults. | 230 // defaults. |
231 ASSERT_TRUE(TitlesMatch(*extension.get(), *action)); | 231 ASSERT_TRUE(TitlesMatch(*extension.get(), *action)); |
232 ASSERT_TRUE(IconsMatch(*extension.get(), 48, *action, 38)); | 232 ASSERT_TRUE(IconsMatch(*extension.get(), 48, *action, 38)); |
233 } | 233 } |
234 | 234 |
235 } // namespace | 235 } // namespace |
236 } // namespace extensions | 236 } // namespace extensions |
OLD | NEW |