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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
7 #include "chrome/test/base/testing_browser_process.h"
8 #include "chrome/test/base/testing_profile.h"
9 #include "chrome/test/base/testing_profile_manager.h"
10 #include "components/drive/dummy_file_system.h"
11 #include "components/drive/service/dummy_drive_service.h"
12 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "content/public/test/test_utils.h"
14 #include "testing/gtest/include/gtest/gtest.h"
19 const char kTestProfileName
[] = "test-profile";
22 class DriveIntegrationServiceTest
: public testing::Test
{
24 DriveIntegrationServiceTest()
25 : profile_manager_(TestingBrowserProcess::GetGlobal()) {}
27 void SetUp() override
{ ASSERT_TRUE(profile_manager_
.SetUp()); }
30 content::TestBrowserThreadBundle thread_bundle_
;
31 // DriveIntegrationService depends on DriveNotificationManager which depends
32 // on InvalidationService. On Chrome OS, the InvalidationServiceFactory
33 // uses chromeos::ProfileHelper, which needs the ProfileManager or a
34 // TestProfileManager to be running.
35 TestingProfileManager profile_manager_
;
38 TEST_F(DriveIntegrationServiceTest
, InitializeAndShutdown
) {
39 scoped_ptr
<DriveIntegrationService
> integration_service(
40 new DriveIntegrationService(
41 profile_manager_
.CreateTestingProfile(kTestProfileName
),
43 new DummyDriveService
,
46 new DummyFileSystem
));
47 integration_service
->SetEnabled(true);
48 content::RunAllBlockingPoolTasksUntilIdle();
49 integration_service
->Shutdown();
52 TEST_F(DriveIntegrationServiceTest
, ServiceInstanceIdentity
) {
53 TestingProfile
* user1
= profile_manager_
.CreateTestingProfile("user1");
55 // Integration Service is created as a profile keyed service.
56 EXPECT_TRUE(DriveIntegrationServiceFactory::GetForProfile(user1
));
58 // Shares the same instance with the incognito mode profile.
59 Profile
* user1_incognito
= user1
->GetOffTheRecordProfile();
60 EXPECT_EQ(DriveIntegrationServiceFactory::GetForProfile(user1
),
61 DriveIntegrationServiceFactory::GetForProfile(user1_incognito
));
63 // For different profiles, different services are running.
64 TestingProfile
* user2
= profile_manager_
.CreateTestingProfile("user2");
65 EXPECT_NE(DriveIntegrationServiceFactory::GetForProfile(user1
),
66 DriveIntegrationServiceFactory::GetForProfile(user2
));