1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/message_loop/message_loop.h"
6 #include "base/run_loop.h"
7 #include "base/synchronization/waitable_event.h"
8 #include "base/time/time.h"
9 #include "chrome/browser/sync/profile_sync_service.h"
10 #include "chrome/browser/sync/test/integration/sync_test.h"
11 #include "content/public/browser/browser_thread.h"
13 using content::BrowserThread
;
15 class SingleClientDirectorySyncTest
: public SyncTest
{
17 SingleClientDirectorySyncTest() : SyncTest(SINGLE_CLIENT
) {}
18 ~SingleClientDirectorySyncTest() override
{}
21 DISALLOW_COPY_AND_ASSIGN(SingleClientDirectorySyncTest
);
24 void SignalEvent(base::WaitableEvent
* e
) {
28 bool WaitForExistingTasksOnLoop(base::MessageLoop
* loop
) {
29 base::WaitableEvent
e(true, false);
30 loop
->PostTask(FROM_HERE
, base::Bind(&SignalEvent
, &e
));
31 // Timeout stolen from StatusChangeChecker::GetTimeoutDuration().
32 return e
.TimedWait(base::TimeDelta::FromSeconds(45));
35 IN_PROC_BROWSER_TEST_F(SingleClientDirectorySyncTest
,
36 StopThenDisableDeletesDirectory
) {
37 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
38 ProfileSyncService
* sync_service
= GetSyncService(0);
39 base::FilePath directory_path
= sync_service
->GetDirectoryPathForTest();
40 ASSERT_TRUE(base::DirectoryExists(directory_path
));
41 sync_service
->StopAndSuppress();
42 sync_service
->DisableForUser();
44 // Wait for StartupController::StartUp()'s tasks to finish.
45 base::RunLoop run_loop
;
46 base::MessageLoop::current()->PostTask(FROM_HERE
, run_loop
.QuitClosure());
48 // Wait for the directory deletion to finish.
49 base::MessageLoop
* sync_loop
= sync_service
->GetSyncLoopForTest();
50 ASSERT_TRUE(WaitForExistingTasksOnLoop(sync_loop
));
52 ASSERT_FALSE(base::DirectoryExists(directory_path
));