| 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "base/version.h" | 12 #include "base/version.h" |
| 13 #include "chrome/browser/extensions/extension_management.h" | 13 #include "chrome/browser/extensions/extension_management.h" |
| 14 #include "chrome/browser/extensions/external_policy_loader.h" | 14 #include "chrome/browser/extensions/external_policy_loader.h" |
| 15 #include "chrome/browser/extensions/external_provider_impl.h" | 15 #include "chrome/browser/extensions/external_provider_impl.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 17 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 17 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
| 18 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
| 19 #include "extensions/browser/external_install_info.h" |
| 19 #include "extensions/browser/external_provider_interface.h" | 20 #include "extensions/browser/external_provider_interface.h" |
| 20 #include "extensions/browser/pref_names.h" | 21 #include "extensions/browser/pref_names.h" |
| 21 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
| 22 #include "extensions/common/manifest.h" | 23 #include "extensions/common/manifest.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 25 |
| 25 using content::BrowserThread; | 26 using content::BrowserThread; |
| 26 | 27 |
| 27 namespace extensions { | 28 namespace extensions { |
| 28 | 29 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 Manifest::EXTERNAL_POLICY_DOWNLOAD, | 64 Manifest::EXTERNAL_POLICY_DOWNLOAD, |
| 64 Extension::NO_FLAGS)); | 65 Extension::NO_FLAGS)); |
| 65 | 66 |
| 66 // Extensions will be removed from this list as they visited, | 67 // Extensions will be removed from this list as they visited, |
| 67 // so it should be emptied by the end. | 68 // so it should be emptied by the end. |
| 68 expected_extensions_ = expected_extensions; | 69 expected_extensions_ = expected_extensions; |
| 69 provider_->VisitRegisteredExtension(); | 70 provider_->VisitRegisteredExtension(); |
| 70 EXPECT_TRUE(expected_extensions_.empty()); | 71 EXPECT_TRUE(expected_extensions_.empty()); |
| 71 } | 72 } |
| 72 | 73 |
| 73 bool OnExternalExtensionFileFound(const std::string& id, | 74 bool OnExternalExtensionFileFound( |
| 74 const Version* version, | 75 const extensions::ExternalInstallInfoFile& info) override { |
| 75 const base::FilePath& path, | |
| 76 Manifest::Location unused, | |
| 77 int unused2, | |
| 78 bool unused3, | |
| 79 bool unused4) override { | |
| 80 ADD_FAILURE() << "There should be no external extensions from files."; | 76 ADD_FAILURE() << "There should be no external extensions from files."; |
| 81 return false; | 77 return false; |
| 82 } | 78 } |
| 83 | 79 |
| 84 bool OnExternalExtensionUpdateUrlFound(const std::string& id, | 80 bool OnExternalExtensionUpdateUrlFound( |
| 85 const std::string& install_parameter, | 81 const extensions::ExternalInstallInfoUpdateUrl& info, |
| 86 const GURL& update_url, | 82 bool is_initial_load) override { |
| 87 Manifest::Location location, | |
| 88 int unused1, | |
| 89 bool unused2) override { | |
| 90 // Extension has the correct location. | 83 // Extension has the correct location. |
| 91 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, location); | 84 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, info.download_location); |
| 92 | 85 |
| 93 // Provider returns the correct location when asked. | 86 // Provider returns the correct location when asked. |
| 94 Manifest::Location location1; | 87 Manifest::Location location1; |
| 95 scoped_ptr<Version> version1; | 88 scoped_ptr<Version> version1; |
| 96 provider_->GetExtensionDetails(id, &location1, &version1); | 89 provider_->GetExtensionDetails(info.extension_id, &location1, &version1); |
| 97 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, location1); | 90 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, location1); |
| 98 EXPECT_FALSE(version1.get()); | 91 EXPECT_FALSE(version1.get()); |
| 99 | 92 |
| 100 // Remove the extension from our list. | 93 // Remove the extension from our list. |
| 101 EXPECT_EQ(1U, expected_extensions_.erase(id)); | 94 EXPECT_EQ(1U, expected_extensions_.erase(info.extension_id)); |
| 102 return true; | 95 return true; |
| 103 } | 96 } |
| 104 | 97 |
| 105 void OnExternalProviderReady( | 98 void OnExternalProviderReady( |
| 106 const ExternalProviderInterface* provider) override { | 99 const ExternalProviderInterface* provider) override { |
| 107 EXPECT_EQ(provider, provider_.get()); | 100 EXPECT_EQ(provider, provider_.get()); |
| 108 EXPECT_TRUE(provider->IsReady()); | 101 EXPECT_TRUE(provider->IsReady()); |
| 109 } | 102 } |
| 110 | 103 |
| 104 void OnExternalProviderUpdateComplete( |
| 105 const ExternalProviderInterface* provider, |
| 106 const ScopedVector<ExternalInstallInfoUpdateUrl>& update_url_extensions, |
| 107 const ScopedVector<ExternalInstallInfoFile>& file_extensions, |
| 108 const std::set<std::string>& removed_extensions) override { |
| 109 ADD_FAILURE() << "Only win registry provider is expected to call this."; |
| 110 } |
| 111 |
| 111 private: | 112 private: |
| 112 std::set<std::string> expected_extensions_; | 113 std::set<std::string> expected_extensions_; |
| 113 | 114 |
| 114 scoped_ptr<TestingProfile> profile_; | 115 scoped_ptr<TestingProfile> profile_; |
| 115 | 116 |
| 116 scoped_ptr<ExternalProviderImpl> provider_; | 117 scoped_ptr<ExternalProviderImpl> provider_; |
| 117 | 118 |
| 118 DISALLOW_COPY_AND_ASSIGN(MockExternalPolicyProviderVisitor); | 119 DISALLOW_COPY_AND_ASSIGN(MockExternalPolicyProviderVisitor); |
| 119 }; | 120 }; |
| 120 | 121 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 147 forced_extensions.SetString("invalid", "http://www.example.com/crx"); | 148 forced_extensions.SetString("invalid", "http://www.example.com/crx"); |
| 148 forced_extensions.SetString("dddddddddddddddddddddddddddddddd", | 149 forced_extensions.SetString("dddddddddddddddddddddddddddddddd", |
| 149 std::string()); | 150 std::string()); |
| 150 forced_extensions.SetString("invalid", "bad"); | 151 forced_extensions.SetString("invalid", "bad"); |
| 151 | 152 |
| 152 MockExternalPolicyProviderVisitor mv; | 153 MockExternalPolicyProviderVisitor mv; |
| 153 mv.Visit(forced_extensions, expected_extensions); | 154 mv.Visit(forced_extensions, expected_extensions); |
| 154 } | 155 } |
| 155 | 156 |
| 156 } // namespace extensions | 157 } // namespace extensions |
| OLD | NEW |