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/app_list/apps_model_builder.h" | 5 #include "chrome/browser/ui/app_list/apps_model_builder.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/prefs/pref_service.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/extension_function_test_utils.h" |
12 #include "chrome/browser/extensions/extension_service_unittest.h" | 14 #include "chrome/browser/extensions/extension_service_unittest.h" |
13 #include "chrome/browser/extensions/extension_sorting.h" | 15 #include "chrome/browser/extensions/extension_sorting.h" |
| 16 #include "chrome/common/extensions/extension_constants.h" |
| 17 #include "chrome/common/extensions/manifest.h" |
| 18 #include "chrome/common/pref_names.h" |
14 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "ui/app_list/app_list_item_model.h" | 21 #include "ui/app_list/app_list_item_model.h" |
17 | 22 |
18 namespace { | 23 namespace { |
19 | 24 |
20 const char kHostedAppId[] = "dceacbkfkmllgmjmbhgkpjegnodmildf"; | 25 const char kHostedAppId[] = "dceacbkfkmllgmjmbhgkpjegnodmildf"; |
21 const char kPackagedApp1Id[] = "emfkafnhnpcmabnnkckkchdilgeoekbo"; | 26 const char kPackagedApp1Id[] = "emfkafnhnpcmabnnkckkchdilgeoekbo"; |
22 const char kPackagedApp2Id[] = "jlklkagmeajbjiobondfhiekepofmljl"; | 27 const char kPackagedApp2Id[] = "jlklkagmeajbjiobondfhiekepofmljl"; |
23 | 28 |
24 // Get a string of all apps in |model| joined with ','. | 29 // Get a string of all apps in |model| joined with ','. |
25 std::string GetModelContent(app_list::AppListModel::Apps* model) { | 30 std::string GetModelContent(app_list::AppListModel::Apps* model) { |
26 std::string content; | 31 std::string content; |
27 for (size_t i = 0; i < model->item_count(); ++i) { | 32 for (size_t i = 0; i < model->item_count(); ++i) { |
28 if (i > 0) | 33 if (i > 0) |
29 content += ','; | 34 content += ','; |
30 content += model->GetItemAt(i)->title(); | 35 content += model->GetItemAt(i)->title(); |
31 } | 36 } |
32 return content; | 37 return content; |
33 } | 38 } |
34 | 39 |
| 40 scoped_refptr<extensions::Extension> MakeApp(const std::string& name, |
| 41 const std::string& version, |
| 42 const std::string& url, |
| 43 const std::string& id) { |
| 44 std::string err; |
| 45 DictionaryValue value; |
| 46 value.SetString("name", name); |
| 47 value.SetString("version", version); |
| 48 value.SetString("app.launch.web_url", url); |
| 49 scoped_refptr<extensions::Extension> app = |
| 50 extensions::Extension::Create( |
| 51 base::FilePath(), |
| 52 extensions::Manifest::INTERNAL, |
| 53 value, |
| 54 extensions::Extension::WAS_INSTALLED_BY_DEFAULT, |
| 55 id, |
| 56 &err); |
| 57 EXPECT_EQ(err, ""); |
| 58 return app; |
| 59 } |
| 60 |
35 } // namespace | 61 } // namespace |
36 | 62 |
37 class AppsModelBuilderTest : public ExtensionServiceTestBase { | 63 class AppsModelBuilderTest : public ExtensionServiceTestBase { |
38 public: | 64 public: |
39 AppsModelBuilderTest() {} | 65 AppsModelBuilderTest() {} |
40 virtual ~AppsModelBuilderTest() {} | 66 virtual ~AppsModelBuilderTest() {} |
41 | 67 |
42 virtual void SetUp() OVERRIDE { | 68 virtual void SetUp() OVERRIDE { |
43 // Load "app_list" extensions test profile. | 69 // Load "app_list" extensions test profile. |
44 // The test profile has 4 extensions: | 70 // The test profile has 4 extensions: |
(...skipping 17 matching lines...) Expand all Loading... |
62 scoped_ptr<app_list::AppListModel::Apps> model( | 88 scoped_ptr<app_list::AppListModel::Apps> model( |
63 new app_list::AppListModel::Apps); | 89 new app_list::AppListModel::Apps); |
64 AppsModelBuilder builder(profile_.get(), model.get(), NULL); | 90 AppsModelBuilder builder(profile_.get(), model.get(), NULL); |
65 builder.Build(); | 91 builder.Build(); |
66 | 92 |
67 // The apps list would have 3 extension apps in the profile. | 93 // The apps list would have 3 extension apps in the profile. |
68 EXPECT_EQ(std::string("Packaged App 1,Packaged App 2,Hosted App"), | 94 EXPECT_EQ(std::string("Packaged App 1,Packaged App 2,Hosted App"), |
69 GetModelContent(model.get())); | 95 GetModelContent(model.get())); |
70 } | 96 } |
71 | 97 |
| 98 TEST_F(AppsModelBuilderTest, HideWebStore) { |
| 99 // Install a "web store" app. |
| 100 scoped_refptr<extensions::Extension> store = |
| 101 MakeApp("webstore", |
| 102 "0.0", |
| 103 "http://google.com", |
| 104 std::string(extension_misc::kWebStoreAppId)); |
| 105 service_->AddExtension(store); |
| 106 |
| 107 // Install an "enterprise web store" app. |
| 108 scoped_refptr<extensions::Extension> enterprise_store = |
| 109 MakeApp("enterprise_webstore", |
| 110 "0.0", |
| 111 "http://google.com", |
| 112 std::string(extension_misc::kEnterpriseWebStoreAppId)); |
| 113 service_->AddExtension(enterprise_store); |
| 114 |
| 115 // Web stores should be present in the AppListModel. |
| 116 app_list::AppListModel::Apps model1; |
| 117 AppsModelBuilder builder1(profile_.get(), &model1, NULL); |
| 118 builder1.Build(); |
| 119 std::string content = GetModelContent(&model1); |
| 120 EXPECT_NE(std::string::npos, content.find("webstore")); |
| 121 EXPECT_NE(std::string::npos, content.find("enterprise_webstore")); |
| 122 |
| 123 // Activate the HideWebStoreIcon policy. |
| 124 profile_->GetPrefs()->SetBoolean(prefs::kHideWebStoreIcon, true); |
| 125 |
| 126 // Web stores should NOT be in the AppListModel. |
| 127 app_list::AppListModel::Apps model2; |
| 128 AppsModelBuilder builder2(profile_.get(), &model2, NULL); |
| 129 builder2.Build(); |
| 130 content = GetModelContent(&model2); |
| 131 EXPECT_EQ(std::string::npos, content.find("webstore")); |
| 132 EXPECT_EQ(std::string::npos, content.find("enterprise_webstore")); |
| 133 } |
| 134 |
72 TEST_F(AppsModelBuilderTest, DisableAndEnable) { | 135 TEST_F(AppsModelBuilderTest, DisableAndEnable) { |
73 scoped_ptr<app_list::AppListModel::Apps> model( | 136 scoped_ptr<app_list::AppListModel::Apps> model( |
74 new app_list::AppListModel::Apps); | 137 new app_list::AppListModel::Apps); |
75 AppsModelBuilder builder(profile_.get(), model.get(), NULL); | 138 AppsModelBuilder builder(profile_.get(), model.get(), NULL); |
76 builder.Build(); | 139 builder.Build(); |
77 | 140 |
78 service_->DisableExtension(kHostedAppId, | 141 service_->DisableExtension(kHostedAppId, |
79 extensions::Extension::DISABLE_NONE); | 142 extensions::Extension::DISABLE_NONE); |
80 EXPECT_EQ(std::string("Packaged App 1,Packaged App 2,Hosted App"), | 143 EXPECT_EQ(std::string("Packaged App 1,Packaged App 2,Hosted App"), |
81 GetModelContent(model.get())); | 144 GetModelContent(model.get())); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 "page_ordinal", | 221 "page_ordinal", |
159 base::Value::CreateStringValue("a corrupted ordinal")); | 222 base::Value::CreateStringValue("a corrupted ordinal")); |
160 | 223 |
161 scoped_ptr<app_list::AppListModel::Apps> model( | 224 scoped_ptr<app_list::AppListModel::Apps> model( |
162 new app_list::AppListModel::Apps); | 225 new app_list::AppListModel::Apps); |
163 AppsModelBuilder builder(profile_.get(), model.get(), NULL); | 226 AppsModelBuilder builder(profile_.get(), model.get(), NULL); |
164 | 227 |
165 // This should not assert or crash. | 228 // This should not assert or crash. |
166 builder.Build(); | 229 builder.Build(); |
167 } | 230 } |
OLD | NEW |