OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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. |
| 4 |
| 5 #include "base/bind.h" |
| 6 #include "base/files/file_path.h" |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/app_list/profile_loader.h" |
| 10 #include "chrome/browser/ui/app_list/test/fake_keep_alive_service.h" |
| 11 #include "chrome/browser/ui/app_list/test/fake_profile.h" |
| 12 #include "chrome/browser/ui/app_list/test/fake_profile_store.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 class ProfileLoaderUnittest : public testing::Test { |
| 16 public: |
| 17 virtual void SetUp() OVERRIDE { |
| 18 last_callback_result_ = NULL; |
| 19 profile1_.reset( |
| 20 new FakeProfile("p1", base::FilePath(FILE_PATH_LITERAL("profile1")))); |
| 21 profile2_.reset( |
| 22 new FakeProfile("p2", base::FilePath(FILE_PATH_LITERAL("profile2")))); |
| 23 |
| 24 profile_store_.reset(new FakeProfileStore( |
| 25 base::FilePath(FILE_PATH_LITERAL("udd")))); |
| 26 keep_alive_service_ = new FakeKeepAliveService; |
| 27 loader_.reset(new ProfileLoader( |
| 28 profile_store_.get(), |
| 29 scoped_ptr<KeepAliveService>(keep_alive_service_))); |
| 30 } |
| 31 |
| 32 void StartLoadingProfile(Profile* profile) { |
| 33 loader_->LoadProfileInvalidatingOtherLoads( |
| 34 profile->GetPath(), |
| 35 base::Bind(&ProfileLoaderUnittest::OnProfileLoaded, |
| 36 base::Unretained(this))); |
| 37 } |
| 38 |
| 39 void FinishLoadingProfile(Profile* profile) { |
| 40 profile_store_->LoadProfile(profile); |
| 41 } |
| 42 |
| 43 void OnProfileLoaded(Profile* profile) { |
| 44 last_callback_result_ = profile; |
| 45 } |
| 46 |
| 47 FakeKeepAliveService* keep_alive_service_; |
| 48 scoped_ptr<ProfileLoader> loader_; |
| 49 scoped_ptr<FakeProfileStore> profile_store_; |
| 50 scoped_ptr<FakeProfile> profile1_; |
| 51 scoped_ptr<FakeProfile> profile2_; |
| 52 Profile* last_callback_result_; |
| 53 }; |
| 54 |
| 55 TEST_F(ProfileLoaderUnittest, LoadASecondProfileBeforeTheFirstFinishes) { |
| 56 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 57 |
| 58 StartLoadingProfile(profile1_.get()); |
| 59 EXPECT_TRUE(loader_->IsAnyProfileLoading()); |
| 60 |
| 61 StartLoadingProfile(profile2_.get()); |
| 62 FinishLoadingProfile(profile1_.get()); |
| 63 EXPECT_EQ(NULL, last_callback_result_); |
| 64 |
| 65 FinishLoadingProfile(profile2_.get()); |
| 66 EXPECT_EQ(profile2_.get(), last_callback_result_); |
| 67 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 68 } |
| 69 |
| 70 TEST_F(ProfileLoaderUnittest, TestKeepsAliveWhileLoadingProfiles) { |
| 71 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 72 EXPECT_FALSE(keep_alive_service_->is_keeping_alive()); |
| 73 |
| 74 StartLoadingProfile(profile1_.get()); |
| 75 EXPECT_TRUE(loader_->IsAnyProfileLoading()); |
| 76 EXPECT_TRUE(keep_alive_service_->is_keeping_alive()); |
| 77 |
| 78 FinishLoadingProfile(profile1_.get()); |
| 79 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 80 EXPECT_FALSE(keep_alive_service_->is_keeping_alive()); |
| 81 } |
| 82 |
| 83 TEST_F(ProfileLoaderUnittest, TestKeepsAliveWhileLoadingMultipleProfiles) { |
| 84 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 85 EXPECT_FALSE(keep_alive_service_->is_keeping_alive()); |
| 86 |
| 87 StartLoadingProfile(profile1_.get()); |
| 88 EXPECT_TRUE(loader_->IsAnyProfileLoading()); |
| 89 EXPECT_TRUE(keep_alive_service_->is_keeping_alive()); |
| 90 |
| 91 StartLoadingProfile(profile2_.get()); |
| 92 EXPECT_TRUE(loader_->IsAnyProfileLoading()); |
| 93 EXPECT_TRUE(keep_alive_service_->is_keeping_alive()); |
| 94 |
| 95 FinishLoadingProfile(profile1_.get()); |
| 96 EXPECT_TRUE(loader_->IsAnyProfileLoading()); |
| 97 EXPECT_TRUE(keep_alive_service_->is_keeping_alive()); |
| 98 |
| 99 FinishLoadingProfile(profile2_.get()); |
| 100 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 101 EXPECT_FALSE(keep_alive_service_->is_keeping_alive()); |
| 102 } |
| 103 |
| 104 TEST_F(ProfileLoaderUnittest, TestInvalidatingCurrentLoad) { |
| 105 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 106 EXPECT_FALSE(keep_alive_service_->is_keeping_alive()); |
| 107 |
| 108 StartLoadingProfile(profile1_.get()); |
| 109 loader_->InvalidatePendingProfileLoads(); |
| 110 // The profile is still considered loading even though we will do nothing when |
| 111 // it gets here. |
| 112 EXPECT_TRUE(loader_->IsAnyProfileLoading()); |
| 113 EXPECT_TRUE(keep_alive_service_->is_keeping_alive()); |
| 114 |
| 115 FinishLoadingProfile(profile1_.get()); |
| 116 EXPECT_EQ(NULL, last_callback_result_); |
| 117 } |
OLD | NEW |