Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 10920017: [Sync] Generalize StringOrdinal to handle ordinal_in_parent field (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Relax tests Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/extensions/extension_service_unittest.h" 5 #include "chrome/browser/extensions/extension_service_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #include "chrome/common/chrome_notification_types.h" 56 #include "chrome/common/chrome_notification_types.h"
57 #include "chrome/common/chrome_paths.h" 57 #include "chrome/common/chrome_paths.h"
58 #include "chrome/common/chrome_switches.h" 58 #include "chrome/common/chrome_switches.h"
59 #include "chrome/common/extensions/extension.h" 59 #include "chrome/common/extensions/extension.h"
60 #include "chrome/common/extensions/extension_l10n_util.h" 60 #include "chrome/common/extensions/extension_l10n_util.h"
61 #include "chrome/common/extensions/extension_manifest_constants.h" 61 #include "chrome/common/extensions/extension_manifest_constants.h"
62 #include "chrome/common/extensions/extension_resource.h" 62 #include "chrome/common/extensions/extension_resource.h"
63 #include "chrome/common/extensions/permissions/permission_set.h" 63 #include "chrome/common/extensions/permissions/permission_set.h"
64 #include "chrome/common/extensions/url_pattern.h" 64 #include "chrome/common/extensions/url_pattern.h"
65 #include "chrome/common/pref_names.h" 65 #include "chrome/common/pref_names.h"
66 #include "chrome/common/string_ordinal.h"
67 #include "chrome/common/url_constants.h" 66 #include "chrome/common/url_constants.h"
68 #include "chrome/test/base/testing_profile.h" 67 #include "chrome/test/base/testing_profile.h"
69 #include "content/public/browser/dom_storage_context.h" 68 #include "content/public/browser/dom_storage_context.h"
70 #include "content/public/browser/indexed_db_context.h" 69 #include "content/public/browser/indexed_db_context.h"
71 #include "content/public/browser/notification_registrar.h" 70 #include "content/public/browser/notification_registrar.h"
72 #include "content/public/browser/notification_service.h" 71 #include "content/public/browser/notification_service.h"
73 #include "content/public/browser/plugin_service.h" 72 #include "content/public/browser/plugin_service.h"
74 #include "content/public/browser/storage_partition.h" 73 #include "content/public/browser/storage_partition.h"
75 #include "content/public/common/content_constants.h" 74 #include "content/public/common/content_constants.h"
76 #include "content/public/test/test_browser_thread.h" 75 #include "content/public/test/test_browser_thread.h"
77 #include "googleurl/src/gurl.h" 76 #include "googleurl/src/gurl.h"
78 #include "grit/browser_resources.h" 77 #include "grit/browser_resources.h"
79 #include "net/cookies/canonical_cookie.h" 78 #include "net/cookies/canonical_cookie.h"
80 #include "net/cookies/cookie_monster.h" 79 #include "net/cookies/cookie_monster.h"
81 #include "net/cookies/cookie_options.h" 80 #include "net/cookies/cookie_options.h"
82 #include "net/url_request/url_request_context.h" 81 #include "net/url_request/url_request_context.h"
83 #include "net/url_request/url_request_context_getter.h" 82 #include "net/url_request/url_request_context_getter.h"
83 #include "sync/api/string_ordinal.h"
84 #include "sync/api/sync_error_factory.h" 84 #include "sync/api/sync_error_factory.h"
85 #include "sync/api/sync_error_factory_mock.h" 85 #include "sync/api/sync_error_factory_mock.h"
86 #include "sync/protocol/app_specifics.pb.h" 86 #include "sync/protocol/app_specifics.pb.h"
87 #include "sync/protocol/extension_specifics.pb.h" 87 #include "sync/protocol/extension_specifics.pb.h"
88 #include "sync/protocol/sync.pb.h" 88 #include "sync/protocol/sync.pb.h"
89 #include "testing/gtest/include/gtest/gtest.h" 89 #include "testing/gtest/include/gtest/gtest.h"
90 #include "testing/platform_test.h" 90 #include "testing/platform_test.h"
91 #include "webkit/database/database_tracker.h" 91 #include "webkit/database/database_tracker.h"
92 #include "webkit/database/database_util.h" 92 #include "webkit/database/database_util.h"
93 #include "webkit/plugins/npapi/mock_plugin_list.h" 93 #include "webkit/plugins/npapi/mock_plugin_list.h"
(...skipping 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 FilePath extensions_path = data_dir_.AppendASCII("app_update"); 2097 FilePath extensions_path = data_dir_.AppendASCII("app_update");
2098 2098
2099 // First install v1 of a hosted app. 2099 // First install v1 of a hosted app.
2100 const Extension* extension = 2100 const Extension* extension =
2101 InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW); 2101 InstallCRX(extensions_path.AppendASCII("v1.crx"), INSTALL_NEW);
2102 ASSERT_EQ(1u, service_->extensions()->size()); 2102 ASSERT_EQ(1u, service_->extensions()->size());
2103 std::string id = extension->id(); 2103 std::string id = extension->id();
2104 ASSERT_EQ(std::string("1"), extension->version()->GetString()); 2104 ASSERT_EQ(std::string("1"), extension->version()->GetString());
2105 2105
2106 // Modify the ordinals so we can distinguish them from the defaults. 2106 // Modify the ordinals so we can distinguish them from the defaults.
2107 StringOrdinal new_page_ordinal = sorting->GetPageOrdinal(id).CreateAfter(); 2107 syncer::StringOrdinal new_page_ordinal =
2108 StringOrdinal new_launch_ordinal = 2108 sorting->GetPageOrdinal(id).CreateAfter();
2109 syncer::StringOrdinal new_launch_ordinal =
2109 sorting->GetAppLaunchOrdinal(id).CreateBefore(); 2110 sorting->GetAppLaunchOrdinal(id).CreateBefore();
2110 2111
2111 sorting->SetPageOrdinal(id, new_page_ordinal); 2112 sorting->SetPageOrdinal(id, new_page_ordinal);
2112 sorting->SetAppLaunchOrdinal(id, new_launch_ordinal); 2113 sorting->SetAppLaunchOrdinal(id, new_launch_ordinal);
2113 2114
2114 // Now try updating to v2. 2115 // Now try updating to v2.
2115 UpdateExtension(id, extensions_path.AppendASCII("v2.crx"), ENABLED); 2116 UpdateExtension(id, extensions_path.AppendASCII("v2.crx"), ENABLED);
2116 ASSERT_EQ(std::string("2"), 2117 ASSERT_EQ(std::string("2"),
2117 service_->GetExtensionById(id, false)->version()->GetString()); 2118 service_->GetExtensionById(id, false)->version()->GetString());
2118 2119
2119 // Verify that the ordinals match. 2120 // Verify that the ordinals match.
2120 ASSERT_TRUE(new_page_ordinal.Equal(sorting->GetPageOrdinal(id))); 2121 ASSERT_TRUE(new_page_ordinal.Equals(sorting->GetPageOrdinal(id)));
2121 ASSERT_TRUE(new_launch_ordinal.Equal(sorting->GetAppLaunchOrdinal(id))); 2122 ASSERT_TRUE(new_launch_ordinal.Equals(sorting->GetAppLaunchOrdinal(id)));
2122 } 2123 }
2123 2124
2124 // Ensures that the CWS has properly initialized ordinals. 2125 // Ensures that the CWS has properly initialized ordinals.
2125 TEST_F(ExtensionServiceTest, EnsureCWSOrdinalsInitialized) { 2126 TEST_F(ExtensionServiceTest, EnsureCWSOrdinalsInitialized) {
2126 InitializeEmptyExtensionService(); 2127 InitializeEmptyExtensionService();
2127 service_->component_loader()->Add(IDR_WEBSTORE_MANIFEST, 2128 service_->component_loader()->Add(IDR_WEBSTORE_MANIFEST,
2128 FilePath(FILE_PATH_LITERAL("web_store"))); 2129 FilePath(FILE_PATH_LITERAL("web_store")));
2129 service_->Init(); 2130 service_->Init();
2130 2131
2131 ExtensionSorting* sorting = service_->extension_prefs()->extension_sorting(); 2132 ExtensionSorting* sorting = service_->extension_prefs()->extension_sorting();
(...skipping 2423 matching lines...) Expand 10 before | Expand all | Expand 10 after
4555 const Extension* app = 4556 const Extension* app =
4556 PackAndInstallCRX(data_dir_.AppendASCII("app"), INSTALL_NEW); 4557 PackAndInstallCRX(data_dir_.AppendASCII("app"), INSTALL_NEW);
4557 ASSERT_TRUE(app); 4558 ASSERT_TRUE(app);
4558 ASSERT_TRUE(app->is_app()); 4559 ASSERT_TRUE(app->is_app());
4559 4560
4560 TestSyncProcessorStub processor; 4561 TestSyncProcessorStub processor;
4561 service_->MergeDataAndStartSyncing(syncer::APPS, syncer::SyncDataList(), 4562 service_->MergeDataAndStartSyncing(syncer::APPS, syncer::SyncDataList(),
4562 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), 4563 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub),
4563 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 4564 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
4564 4565
4565 StringOrdinal initial_ordinal = StringOrdinal::CreateInitialOrdinal(); 4566 syncer::StringOrdinal initial_ordinal =
4567 syncer::StringOrdinal::CreateInitialOrdinal();
4566 { 4568 {
4567 syncer::SyncDataList list = service_->GetAllSyncData(syncer::APPS); 4569 syncer::SyncDataList list = service_->GetAllSyncData(syncer::APPS);
4568 ASSERT_EQ(list.size(), 1U); 4570 ASSERT_EQ(list.size(), 1U);
4569 4571
4570 extensions::AppSyncData app_sync_data(list[0]); 4572 extensions::AppSyncData app_sync_data(list[0]);
4571 EXPECT_TRUE(initial_ordinal.Equal(app_sync_data.app_launch_ordinal())); 4573 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.app_launch_ordinal()));
4572 EXPECT_TRUE(initial_ordinal.Equal(app_sync_data.page_ordinal())); 4574 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal()));
4573 } 4575 }
4574 4576
4575 ExtensionSorting* sorting = service_->extension_prefs()->extension_sorting(); 4577 ExtensionSorting* sorting = service_->extension_prefs()->extension_sorting();
4576 sorting->SetAppLaunchOrdinal(app->id(), initial_ordinal.CreateAfter()); 4578 sorting->SetAppLaunchOrdinal(app->id(), initial_ordinal.CreateAfter());
4577 { 4579 {
4578 syncer::SyncDataList list = service_->GetAllSyncData(syncer::APPS); 4580 syncer::SyncDataList list = service_->GetAllSyncData(syncer::APPS);
4579 ASSERT_EQ(list.size(), 1U); 4581 ASSERT_EQ(list.size(), 1U);
4580 4582
4581 extensions::AppSyncData app_sync_data(list[0]); 4583 extensions::AppSyncData app_sync_data(list[0]);
4582 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal())); 4584 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal()));
4583 EXPECT_TRUE(initial_ordinal.Equal(app_sync_data.page_ordinal())); 4585 EXPECT_TRUE(initial_ordinal.Equals(app_sync_data.page_ordinal()));
4584 } 4586 }
4585 4587
4586 sorting->SetPageOrdinal(app->id(), initial_ordinal.CreateAfter()); 4588 sorting->SetPageOrdinal(app->id(), initial_ordinal.CreateAfter());
4587 { 4589 {
4588 syncer::SyncDataList list = service_->GetAllSyncData(syncer::APPS); 4590 syncer::SyncDataList list = service_->GetAllSyncData(syncer::APPS);
4589 ASSERT_EQ(list.size(), 1U); 4591 ASSERT_EQ(list.size(), 1U);
4590 4592
4591 extensions::AppSyncData app_sync_data(list[0]); 4593 extensions::AppSyncData app_sync_data(list[0]);
4592 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal())); 4594 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.app_launch_ordinal()));
4593 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.page_ordinal())); 4595 EXPECT_TRUE(initial_ordinal.LessThan(app_sync_data.page_ordinal()));
(...skipping 23 matching lines...) Expand all
4617 ASSERT_EQ(list.size(), 3U); 4619 ASSERT_EQ(list.size(), 3U);
4618 4620
4619 extensions::AppSyncData data[kAppCount]; 4621 extensions::AppSyncData data[kAppCount];
4620 for (size_t i = 0; i < kAppCount; ++i) { 4622 for (size_t i = 0; i < kAppCount; ++i) {
4621 data[i] = extensions::AppSyncData(list[i]); 4623 data[i] = extensions::AppSyncData(list[i]);
4622 } 4624 }
4623 4625
4624 // The sync data is not always in the same order our apps were installed in, 4626 // The sync data is not always in the same order our apps were installed in,
4625 // so we do that sorting here so we can make sure the values are changed as 4627 // so we do that sorting here so we can make sure the values are changed as
4626 // expected. 4628 // expected.
4627 StringOrdinal app_launch_ordinals[kAppCount]; 4629 syncer::StringOrdinal app_launch_ordinals[kAppCount];
4628 for (size_t i = 0; i < kAppCount; ++i) { 4630 for (size_t i = 0; i < kAppCount; ++i) {
4629 for (size_t j = 0; j < kAppCount; ++j) { 4631 for (size_t j = 0; j < kAppCount; ++j) {
4630 if (apps[i]->id() == data[j].id()) 4632 if (apps[i]->id() == data[j].id())
4631 app_launch_ordinals[i] = data[j].app_launch_ordinal(); 4633 app_launch_ordinals[i] = data[j].app_launch_ordinal();
4632 } 4634 }
4633 } 4635 }
4634 4636
4635 EXPECT_TRUE(app_launch_ordinals[1].LessThan(app_launch_ordinals[0])); 4637 EXPECT_TRUE(app_launch_ordinals[1].LessThan(app_launch_ordinals[0]));
4636 EXPECT_TRUE(app_launch_ordinals[0].LessThan(app_launch_ordinals[2])); 4638 EXPECT_TRUE(app_launch_ordinals[0].LessThan(app_launch_ordinals[2]));
4637 } 4639 }
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
5416 // This should NOT trigger an alert. 5418 // This should NOT trigger an alert.
5417 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 5419 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
5418 data_dir_.AppendASCII("hosted_app.crx")); 5420 data_dir_.AppendASCII("hosted_app.crx"));
5419 5421
5420 service_->CheckForExternalUpdates(); 5422 service_->CheckForExternalUpdates();
5421 loop_.RunAllPending(); 5423 loop_.RunAllPending();
5422 5424
5423 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); 5425 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get()));
5424 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); 5426 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size());
5425 } 5427 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/extension_sorting.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698