OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/ash/launcher/chrome_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "ash/launcher/launcher_model.h" | 11 #include "ash/launcher/launcher_model.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
19 #include "chrome/browser/extensions/test_extension_system.h" | 19 #include "chrome/browser/extensions/test_extension_system.h" |
20 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 20 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
21 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "chrome/test/base/testing_pref_service.h" | 23 #include "chrome/test/base/testing_pref_service.h" |
24 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
25 #include "content/public/test/test_browser_thread.h" | 25 #include "content/public/test/test_browser_thread.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
27 | 27 |
28 using extensions::Extension; | 28 using extensions::Extension; |
29 | 29 |
| 30 namespace { |
| 31 const int kExpectedAppIndex = 2; |
| 32 } |
| 33 |
30 class ChromeLauncherControllerTest : public testing::Test { | 34 class ChromeLauncherControllerTest : public testing::Test { |
31 protected: | 35 protected: |
32 ChromeLauncherControllerTest() | 36 ChromeLauncherControllerTest() |
33 : ui_thread_(content::BrowserThread::UI, &loop_), | 37 : ui_thread_(content::BrowserThread::UI, &loop_), |
34 file_thread_(content::BrowserThread::FILE, &loop_), | 38 file_thread_(content::BrowserThread::FILE, &loop_), |
35 profile_(new TestingProfile()), | 39 profile_(new TestingProfile()), |
36 extension_service_(NULL) { | 40 extension_service_(NULL) { |
37 DictionaryValue manifest; | 41 DictionaryValue manifest; |
38 manifest.SetString("name", "launcher controller test extension"); | 42 manifest.SetString("name", "launcher controller test extension"); |
39 manifest.SetString("version", "1"); | 43 manifest.SetString("version", "1"); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 122 |
119 // Model should only contain the browser shortcut and app list items. | 123 // Model should only contain the browser shortcut and app list items. |
120 EXPECT_EQ(2, model_.item_count()); | 124 EXPECT_EQ(2, model_.item_count()); |
121 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); | 125 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
122 EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); | 126 EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); |
123 EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); | 127 EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); |
124 | 128 |
125 // Installing |extension3_| should add it to the launcher. | 129 // Installing |extension3_| should add it to the launcher. |
126 extension_service_->AddExtension(extension3_.get()); | 130 extension_service_->AddExtension(extension3_.get()); |
127 EXPECT_EQ(3, model_.item_count()); | 131 EXPECT_EQ(3, model_.item_count()); |
128 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[1].type); | 132 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[kExpectedAppIndex].type); |
129 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); | 133 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
130 EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); | 134 EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); |
131 EXPECT_TRUE(launcher_controller.IsAppPinned(extension3_->id())); | 135 EXPECT_TRUE(launcher_controller.IsAppPinned(extension3_->id())); |
132 } | 136 } |
133 | 137 |
134 TEST_F(ChromeLauncherControllerTest, Policy) { | 138 TEST_F(ChromeLauncherControllerTest, Policy) { |
135 extension_service_->AddExtension(extension1_.get()); | 139 extension_service_->AddExtension(extension1_.get()); |
136 extension_service_->AddExtension(extension3_.get()); | 140 extension_service_->AddExtension(extension3_.get()); |
137 | 141 |
138 base::ListValue policy_value; | 142 base::ListValue policy_value; |
139 InsertPrefValue(&policy_value, 0, extension1_->id()); | 143 InsertPrefValue(&policy_value, 0, extension1_->id()); |
140 InsertPrefValue(&policy_value, 1, extension2_->id()); | 144 InsertPrefValue(&policy_value, 1, extension2_->id()); |
141 profile_->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, | 145 profile_->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, |
142 policy_value.DeepCopy()); | 146 policy_value.DeepCopy()); |
143 | 147 |
144 // Only |extension1_| should get pinned. |extension2_| is specified but not | 148 // Only |extension1_| should get pinned. |extension2_| is specified but not |
145 // installed, and |extension3_| is part of the default set, but that shouldn't | 149 // installed, and |extension3_| is part of the default set, but that shouldn't |
146 // take effect when the policy override is in place. | 150 // take effect when the policy override is in place. |
147 ChromeLauncherController launcher_controller(profile_.get(), &model_); | 151 ChromeLauncherController launcher_controller(profile_.get(), &model_); |
148 launcher_controller.Init(); | 152 launcher_controller.Init(); |
149 EXPECT_EQ(3, model_.item_count()); | 153 EXPECT_EQ(3, model_.item_count()); |
150 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[1].type); | 154 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[kExpectedAppIndex].type); |
151 EXPECT_TRUE(launcher_controller.IsAppPinned(extension1_->id())); | 155 EXPECT_TRUE(launcher_controller.IsAppPinned(extension1_->id())); |
152 EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); | 156 EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); |
153 EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); | 157 EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); |
154 | 158 |
155 // Installing |extension2_| should add it to the launcher. | 159 // Installing |extension2_| should add it to the launcher. |
156 extension_service_->AddExtension(extension2_.get()); | 160 extension_service_->AddExtension(extension2_.get()); |
157 EXPECT_EQ(4, model_.item_count()); | 161 EXPECT_EQ(4, model_.item_count()); |
158 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[1].type); | 162 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[kExpectedAppIndex].type); |
159 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[2].type); | 163 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[2].type); |
160 EXPECT_TRUE(launcher_controller.IsAppPinned(extension1_->id())); | 164 EXPECT_TRUE(launcher_controller.IsAppPinned(extension1_->id())); |
161 EXPECT_TRUE(launcher_controller.IsAppPinned(extension2_->id())); | 165 EXPECT_TRUE(launcher_controller.IsAppPinned(extension2_->id())); |
162 EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); | 166 EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); |
163 | 167 |
164 // Removing |extension1_| from the policy should be reflected in the launcher. | 168 // Removing |extension1_| from the policy should be reflected in the launcher. |
165 policy_value.Remove(0, NULL); | 169 policy_value.Remove(0, NULL); |
166 profile_->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, | 170 profile_->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, |
167 policy_value.DeepCopy()); | 171 policy_value.DeepCopy()); |
168 EXPECT_EQ(3, model_.item_count()); | 172 EXPECT_EQ(3, model_.item_count()); |
169 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[1].type); | 173 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[kExpectedAppIndex].type); |
170 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); | 174 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
171 EXPECT_TRUE(launcher_controller.IsAppPinned(extension2_->id())); | 175 EXPECT_TRUE(launcher_controller.IsAppPinned(extension2_->id())); |
172 EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); | 176 EXPECT_FALSE(launcher_controller.IsAppPinned(extension3_->id())); |
173 } | 177 } |
174 | 178 |
175 TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) { | 179 TEST_F(ChromeLauncherControllerTest, UnpinWithUninstall) { |
176 extension_service_->AddExtension(extension3_.get()); | 180 extension_service_->AddExtension(extension3_.get()); |
177 extension_service_->AddExtension(extension4_.get()); | 181 extension_service_->AddExtension(extension4_.get()); |
178 | 182 |
179 ChromeLauncherController launcher_controller(profile_.get(), &model_); | 183 ChromeLauncherController launcher_controller(profile_.get(), &model_); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 267 |
264 GetAppLaunchers(&controller, &actual_launchers); | 268 GetAppLaunchers(&controller, &actual_launchers); |
265 EXPECT_EQ(expected_launchers, actual_launchers); | 269 EXPECT_EQ(expected_launchers, actual_launchers); |
266 | 270 |
267 // Install |extension2| and verify it shows up between the other two. | 271 // Install |extension2| and verify it shows up between the other two. |
268 extension_service_->AddExtension(extension2_.get()); | 272 extension_service_->AddExtension(extension2_.get()); |
269 expected_launchers.insert(expected_launchers.begin() + 1, extension2_->id()); | 273 expected_launchers.insert(expected_launchers.begin() + 1, extension2_->id()); |
270 GetAppLaunchers(&controller, &actual_launchers); | 274 GetAppLaunchers(&controller, &actual_launchers); |
271 EXPECT_EQ(expected_launchers, actual_launchers); | 275 EXPECT_EQ(expected_launchers, actual_launchers); |
272 } | 276 } |
OLD | NEW |