| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 crx_type = ((i % 2) ? PendingExtensionInfo::EXTENSION | 123 crx_type = ((i % 2) ? PendingExtensionInfo::EXTENSION |
| 124 : PendingExtensionInfo::THEME); | 124 : PendingExtensionInfo::THEME); |
| 125 const bool kIsFromSync = true; | 125 const bool kIsFromSync = true; |
| 126 const bool kInstallSilently = true; | 126 const bool kInstallSilently = true; |
| 127 const Extension::State kInitialState = Extension::ENABLED; | 127 const Extension::State kInitialState = Extension::ENABLED; |
| 128 const bool kInitialIncognitoEnabled = false; | 128 const bool kInitialIncognitoEnabled = false; |
| 129 std::string id = GenerateId(base::StringPrintf("extension%i", i)); | 129 std::string id = GenerateId(base::StringPrintf("extension%i", i)); |
| 130 (*pending_extensions)[id] = | 130 (*pending_extensions)[id] = |
| 131 PendingExtensionInfo(update_url, crx_type, kIsFromSync, | 131 PendingExtensionInfo(update_url, crx_type, kIsFromSync, |
| 132 kInstallSilently, kInitialState, | 132 kInstallSilently, kInitialState, |
| 133 kInitialIncognitoEnabled); | 133 kInitialIncognitoEnabled, Extension::INTERNAL); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 class ServiceForManifestTests : public MockService { | 137 class ServiceForManifestTests : public MockService { |
| 138 public: | 138 public: |
| 139 ServiceForManifestTests() : has_installed_extensions_(false) {} | 139 ServiceForManifestTests() : has_installed_extensions_(false) {} |
| 140 | 140 |
| 141 virtual ~ServiceForManifestTests() {} | 141 virtual ~ServiceForManifestTests() {} |
| 142 | 142 |
| 143 virtual Extension* GetExtensionById(const std::string& id, bool) { | 143 virtual Extension* GetExtensionById(const std::string& id, bool) { |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 const PendingExtensionInfo::ExpectedCrxType kExpectedCrxType = | 561 const PendingExtensionInfo::ExpectedCrxType kExpectedCrxType = |
| 562 PendingExtensionInfo::EXTENSION; | 562 PendingExtensionInfo::EXTENSION; |
| 563 const bool kIsFromSync = true; | 563 const bool kIsFromSync = true; |
| 564 const bool kInstallSilently = true; | 564 const bool kInstallSilently = true; |
| 565 const Extension::State kInitialState = Extension::ENABLED; | 565 const Extension::State kInitialState = Extension::ENABLED; |
| 566 const bool kInitialIncognitoEnabled = false; | 566 const bool kInitialIncognitoEnabled = false; |
| 567 PendingExtensionMap pending_extensions; | 567 PendingExtensionMap pending_extensions; |
| 568 pending_extensions[id] = | 568 pending_extensions[id] = |
| 569 PendingExtensionInfo(test_url, kExpectedCrxType, kIsFromSync, | 569 PendingExtensionInfo(test_url, kExpectedCrxType, kIsFromSync, |
| 570 kInstallSilently, kInitialState, | 570 kInstallSilently, kInitialState, |
| 571 kInitialIncognitoEnabled); | 571 kInitialIncognitoEnabled, Extension::INTERNAL); |
| 572 service.set_pending_extensions(pending_extensions); | 572 service.set_pending_extensions(pending_extensions); |
| 573 } | 573 } |
| 574 | 574 |
| 575 // Call back the ExtensionUpdater with a 200 response and some test data | 575 // Call back the ExtensionUpdater with a 200 response and some test data |
| 576 std::string extension_data("whatever"); | 576 std::string extension_data("whatever"); |
| 577 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); | 577 fetcher = factory.GetFetcherByID(ExtensionUpdater::kExtensionFetcherId); |
| 578 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 578 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 579 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); | 579 EXPECT_TRUE(fetcher->load_flags() == expected_load_flags); |
| 580 fetcher->delegate()->OnURLFetchComplete( | 580 fetcher->delegate()->OnURLFetchComplete( |
| 581 fetcher, test_url, URLRequestStatus(), 200, ResponseCookies(), | 581 fetcher, test_url, URLRequestStatus(), 200, ResponseCookies(), |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 extensions[0]->set_location(Extension::INVALID); | 890 extensions[0]->set_location(Extension::INVALID); |
| 891 builder.AddExtension(*extensions[0]); | 891 builder.AddExtension(*extensions[0]); |
| 892 EXPECT_TRUE(builder.GetFetches().empty()); | 892 EXPECT_TRUE(builder.GetFetches().empty()); |
| 893 STLDeleteElements(&extensions); | 893 STLDeleteElements(&extensions); |
| 894 } | 894 } |
| 895 | 895 |
| 896 // Extensions with invalid update URLs should be rejected. | 896 // Extensions with invalid update URLs should be rejected. |
| 897 builder.AddPendingExtension( | 897 builder.AddPendingExtension( |
| 898 GenerateId("foo"), PendingExtensionInfo(GURL("http:google.com:foo"), | 898 GenerateId("foo"), PendingExtensionInfo(GURL("http:google.com:foo"), |
| 899 PendingExtensionInfo::EXTENSION, | 899 PendingExtensionInfo::EXTENSION, |
| 900 false, false, true, false)); | 900 false, false, true, false, |
| 901 Extension::INTERNAL)); |
| 901 EXPECT_TRUE(builder.GetFetches().empty()); | 902 EXPECT_TRUE(builder.GetFetches().empty()); |
| 902 | 903 |
| 903 // Extensions with empty IDs should be rejected. | 904 // Extensions with empty IDs should be rejected. |
| 904 builder.AddPendingExtension( | 905 builder.AddPendingExtension( |
| 905 "", PendingExtensionInfo(GURL(), PendingExtensionInfo::EXTENSION, | 906 "", PendingExtensionInfo(GURL(), PendingExtensionInfo::EXTENSION, |
| 906 false, false, true, false)); | 907 false, false, true, false, |
| 908 Extension::INTERNAL)); |
| 907 EXPECT_TRUE(builder.GetFetches().empty()); | 909 EXPECT_TRUE(builder.GetFetches().empty()); |
| 908 | 910 |
| 909 // TODO(akalin): Test that extensions with empty update URLs | 911 // TODO(akalin): Test that extensions with empty update URLs |
| 910 // converted from user scripts are rejected. | 912 // converted from user scripts are rejected. |
| 911 | 913 |
| 912 // Extensions with empty update URLs should have a default one | 914 // Extensions with empty update URLs should have a default one |
| 913 // filled in. | 915 // filled in. |
| 914 builder.AddPendingExtension( | 916 builder.AddPendingExtension( |
| 915 GenerateId("foo"), PendingExtensionInfo(GURL(), | 917 GenerateId("foo"), PendingExtensionInfo(GURL(), |
| 916 PendingExtensionInfo::EXTENSION, | 918 PendingExtensionInfo::EXTENSION, |
| 917 false, false, true, false)); | 919 false, false, true, false, |
| 920 Extension::INTERNAL)); |
| 918 std::vector<ManifestFetchData*> fetches = builder.GetFetches(); | 921 std::vector<ManifestFetchData*> fetches = builder.GetFetches(); |
| 919 ASSERT_EQ(1u, fetches.size()); | 922 ASSERT_EQ(1u, fetches.size()); |
| 920 scoped_ptr<ManifestFetchData> fetch(fetches[0]); | 923 scoped_ptr<ManifestFetchData> fetch(fetches[0]); |
| 921 fetches.clear(); | 924 fetches.clear(); |
| 922 EXPECT_FALSE(fetch->base_url().is_empty()); | 925 EXPECT_FALSE(fetch->base_url().is_empty()); |
| 923 EXPECT_FALSE(fetch->full_url().is_empty()); | 926 EXPECT_FALSE(fetch->full_url().is_empty()); |
| 924 } | 927 } |
| 925 | 928 |
| 926 // TODO(asargent) - (http://crbug.com/12780) add tests for: | 929 // TODO(asargent) - (http://crbug.com/12780) add tests for: |
| 927 // -prodversionmin (shouldn't update if browser version too old) | 930 // -prodversionmin (shouldn't update if browser version too old) |
| 928 // -manifests & updates arriving out of order / interleaved | 931 // -manifests & updates arriving out of order / interleaved |
| 929 // -Profile::GetDefaultRequestContext() returning null | 932 // -Profile::GetDefaultRequestContext() returning null |
| 930 // (should not crash, but just do check later) | 933 // (should not crash, but just do check later) |
| 931 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 934 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 932 // -An extension gets uninstalled while updates are in progress (so it doesn't | 935 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 933 // "come back from the dead") | 936 // "come back from the dead") |
| 934 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 937 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 935 // you don't get downgraded accidentally) | 938 // you don't get downgraded accidentally) |
| 936 // -An update manifest mentions multiple updates | 939 // -An update manifest mentions multiple updates |
| OLD | NEW |