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

Side by Side Diff: chrome/browser/sync/test/integration/sync_test.cc

Issue 2835233002: Fix integration tests in src/chrome and src/extensions so that we can turn on IO thread checks wi... (Closed)
Patch Set: ready for review Created 3 years, 8 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
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/sync/test/integration/sync_test.h" 5 #include "chrome/browser/sync/test/integration/sync_test.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
15 #include "base/guid.h" 15 #include "base/guid.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
19 #include "base/path_service.h" 19 #include "base/path_service.h"
20 #include "base/process/launch.h" 20 #include "base/process/launch.h"
21 #include "base/strings/string_split.h" 21 #include "base/strings/string_split.h"
22 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
25 #include "base/synchronization/waitable_event.h" 25 #include "base/synchronization/waitable_event.h"
26 #include "base/test/test_timeouts.h" 26 #include "base/test/test_timeouts.h"
27 #include "base/threading/platform_thread.h" 27 #include "base/threading/platform_thread.h"
28 #include "base/threading/thread_restrictions.h"
28 #include "base/values.h" 29 #include "base/values.h"
29 #include "build/build_config.h" 30 #include "build/build_config.h"
30 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 31 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
31 #include "chrome/browser/chrome_notification_types.h" 32 #include "chrome/browser/chrome_notification_types.h"
32 #include "chrome/browser/history/history_service_factory.h" 33 #include "chrome/browser/history/history_service_factory.h"
33 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" 34 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h"
34 #include "chrome/browser/lifetime/application_lifetime.h" 35 #include "chrome/browser/lifetime/application_lifetime.h"
35 #include "chrome/browser/profiles/profile_manager.h" 36 #include "chrome/browser/profiles/profile_manager.h"
36 #include "chrome/browser/search_engines/template_url_service_factory.h" 37 #include "chrome/browser/search_engines/template_url_service_factory.h"
37 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 38 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 content::WebContents* contents = 332 content::WebContents* contents =
332 browser()->tab_strip_model()->GetActiveWebContents(); 333 browser()->tab_strip_model()->GetActiveWebContents();
333 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); 334 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
334 CHECK(entry) << "Could not get a hold on NavigationEntry post URL navigate."; 335 CHECK(entry) << "Could not get a hold on NavigationEntry post URL navigate.";
335 DVLOG(1) << "Create Gaia account request return code = " 336 DVLOG(1) << "Create Gaia account request return code = "
336 << entry->GetHttpStatusCode(); 337 << entry->GetHttpStatusCode();
337 return entry->GetHttpStatusCode() == 200; 338 return entry->GetHttpStatusCode() == 200;
338 } 339 }
339 340
340 void SyncTest::CreateProfile(int index) { 341 void SyncTest::CreateProfile(int index) {
342 base::ThreadRestrictions::ScopedAllowIO allow_io;
341 tmp_profile_paths_[index] = new base::ScopedTempDir(); 343 tmp_profile_paths_[index] = new base::ScopedTempDir();
342 if (UsingExternalServers() && num_clients_ > 1) { 344 if (UsingExternalServers() && num_clients_ > 1) {
343 // For multi profile UI signin, profile paths should be outside user data 345 // For multi profile UI signin, profile paths should be outside user data
344 // dir to allow signing-in multiple profiles to same account. Otherwise, we 346 // dir to allow signing-in multiple profiles to same account. Otherwise, we
345 // get an error that the profile has already signed in on this device. 347 // get an error that the profile has already signed in on this device.
346 CHECK(tmp_profile_paths_[index]->CreateUniqueTempDir()); 348 CHECK(tmp_profile_paths_[index]->CreateUniqueTempDir());
347 } else { 349 } else {
348 // Create new profiles in user data dir so that other profiles can know 350 // Create new profiles in user data dir so that other profiles can know
349 // about it. This is needed in tests such as supervised user cases which 351 // about it. This is needed in tests such as supervised user cases which
350 // assume browser->profile() as the custodian profile. 352 // assume browser->profile() as the custodian profile.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 if (verifier_ == nullptr) 499 if (verifier_ == nullptr)
498 LOG(FATAL) << "SetupClients() has not yet been called."; 500 LOG(FATAL) << "SetupClients() has not yet been called.";
499 return verifier_; 501 return verifier_;
500 } 502 }
501 503
502 void SyncTest::DisableVerifier() { 504 void SyncTest::DisableVerifier() {
503 use_verifier_ = false; 505 use_verifier_ = false;
504 } 506 }
505 507
506 bool SyncTest::SetupClients() { 508 bool SyncTest::SetupClients() {
509 base::ThreadRestrictions::ScopedAllowIO allow_io;
507 if (num_clients_ <= 0) 510 if (num_clients_ <= 0)
508 LOG(FATAL) << "num_clients_ incorrectly initialized."; 511 LOG(FATAL) << "num_clients_ incorrectly initialized.";
509 if (!profiles_.empty() || !browsers_.empty() || !clients_.empty()) 512 if (!profiles_.empty() || !browsers_.empty() || !clients_.empty())
510 LOG(FATAL) << "SetupClients() has already been called."; 513 LOG(FATAL) << "SetupClients() has already been called.";
511 514
512 // Create the required number of sync profiles, browsers and clients. 515 // Create the required number of sync profiles, browsers and clients.
513 profiles_.resize(num_clients_); 516 profiles_.resize(num_clients_);
514 profile_delegates_.resize(num_clients_ + 1); // + 1 for the verifier. 517 profile_delegates_.resize(num_clients_ + 1); // + 1 for the verifier.
515 tmp_profile_paths_.resize(num_clients_); 518 tmp_profile_paths_.resize(num_clients_);
516 clients_.resize(num_clients_); 519 clients_.resize(num_clients_);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 p2p_invalidation_service->UpdateCredentials(username_, password_); 642 p2p_invalidation_service->UpdateCredentials(username_, password_);
640 // Start listening for and emitting notifications of commits. 643 // Start listening for and emitting notifications of commits.
641 DCHECK(!invalidation_forwarders_[index]); 644 DCHECK(!invalidation_forwarders_[index]);
642 invalidation_forwarders_[index] = 645 invalidation_forwarders_[index] =
643 base::MakeUnique<P2PInvalidationForwarder>(clients_[index]->service(), 646 base::MakeUnique<P2PInvalidationForwarder>(clients_[index]->service(),
644 p2p_invalidation_service); 647 p2p_invalidation_service);
645 } 648 }
646 } 649 }
647 650
648 bool SyncTest::SetupSync() { 651 bool SyncTest::SetupSync() {
652 base::ThreadRestrictions::ScopedAllowIO allow_io;
649 // Create sync profiles and clients if they haven't already been created. 653 // Create sync profiles and clients if they haven't already been created.
650 if (profiles_.empty()) { 654 if (profiles_.empty()) {
651 if (!SetupClients()) { 655 if (!SetupClients()) {
652 LOG(FATAL) << "SetupClients() failed."; 656 LOG(FATAL) << "SetupClients() failed.";
653 return false; 657 return false;
654 } 658 }
655 } 659 }
656 660
657 int clientIndex = 0; 661 int clientIndex = 0;
658 // If we're using external servers, clear server data so the account starts 662 // If we're using external servers, clear server data so the account starts
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 bool SyncTest::ClearServerData(ProfileSyncServiceHarness* harness) { 1216 bool SyncTest::ClearServerData(ProfileSyncServiceHarness* harness) {
1213 // At this point our birthday is good. 1217 // At this point our birthday is good.
1214 base::RunLoop run_loop; 1218 base::RunLoop run_loop;
1215 harness->service()->ClearServerDataForTest(run_loop.QuitClosure()); 1219 harness->service()->ClearServerDataForTest(run_loop.QuitClosure());
1216 run_loop.Run(); 1220 run_loop.Run();
1217 1221
1218 // Our birthday is invalidated on the server here so restart sync to get 1222 // Our birthday is invalidated on the server here so restart sync to get
1219 // the new birthday from the server. 1223 // the new birthday from the server.
1220 return harness->RestartSyncService(); 1224 return harness->RestartSyncService();
1221 } 1225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698