| 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(profile_store_.get(), |
| 28 make_scoped_ptr(keep_alive_service_))); |
| 29 } |
| 30 |
| 31 void StartLoadingProfile(Profile* profile) { |
| 32 loader_->LoadProfileInvalidatingOtherLoads( |
| 33 profile->GetPath(), |
| 34 base::Bind(&ProfileLoaderUnittest::OnProfileLoaded, |
| 35 base::Unretained(this))); |
| 36 } |
| 37 |
| 38 void FinishLoadingProfile(Profile* profile) { |
| 39 profile_store_->LoadProfile(profile); |
| 40 } |
| 41 |
| 42 void OnProfileLoaded(Profile* profile) { |
| 43 last_callback_result_ = profile; |
| 44 } |
| 45 |
| 46 FakeKeepAliveService* keep_alive_service_; |
| 47 scoped_ptr<ProfileLoader> loader_; |
| 48 scoped_ptr<FakeProfileStore> profile_store_; |
| 49 scoped_ptr<FakeProfile> profile1_; |
| 50 scoped_ptr<FakeProfile> profile2_; |
| 51 Profile* last_callback_result_; |
| 52 }; |
| 53 |
| 54 TEST_F(ProfileLoaderUnittest, LoadASecondProfileBeforeTheFirstFinishes) { |
| 55 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 56 |
| 57 StartLoadingProfile(profile1_.get()); |
| 58 EXPECT_TRUE(loader_->IsAnyProfileLoading()); |
| 59 |
| 60 StartLoadingProfile(profile2_.get()); |
| 61 FinishLoadingProfile(profile1_.get()); |
| 62 EXPECT_EQ(NULL, last_callback_result_); |
| 63 |
| 64 FinishLoadingProfile(profile2_.get()); |
| 65 EXPECT_EQ(profile2_.get(), last_callback_result_); |
| 66 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 67 } |
| 68 |
| 69 TEST_F(ProfileLoaderUnittest, TestKeepsAliveWhileLoadingProfiles) { |
| 70 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 71 EXPECT_FALSE(keep_alive_service_->is_keeping_alive()); |
| 72 |
| 73 StartLoadingProfile(profile1_.get()); |
| 74 EXPECT_TRUE(loader_->IsAnyProfileLoading()); |
| 75 EXPECT_TRUE(keep_alive_service_->is_keeping_alive()); |
| 76 |
| 77 FinishLoadingProfile(profile1_.get()); |
| 78 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 79 EXPECT_FALSE(keep_alive_service_->is_keeping_alive()); |
| 80 } |
| 81 |
| 82 TEST_F(ProfileLoaderUnittest, TestKeepsAliveWhileLoadingMultipleProfiles) { |
| 83 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 84 EXPECT_FALSE(keep_alive_service_->is_keeping_alive()); |
| 85 |
| 86 StartLoadingProfile(profile1_.get()); |
| 87 EXPECT_TRUE(loader_->IsAnyProfileLoading()); |
| 88 EXPECT_TRUE(keep_alive_service_->is_keeping_alive()); |
| 89 |
| 90 StartLoadingProfile(profile2_.get()); |
| 91 EXPECT_TRUE(loader_->IsAnyProfileLoading()); |
| 92 EXPECT_TRUE(keep_alive_service_->is_keeping_alive()); |
| 93 |
| 94 FinishLoadingProfile(profile1_.get()); |
| 95 EXPECT_TRUE(loader_->IsAnyProfileLoading()); |
| 96 EXPECT_TRUE(keep_alive_service_->is_keeping_alive()); |
| 97 |
| 98 FinishLoadingProfile(profile2_.get()); |
| 99 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 100 EXPECT_FALSE(keep_alive_service_->is_keeping_alive()); |
| 101 } |
| 102 |
| 103 TEST_F(ProfileLoaderUnittest, TestInvalidatingCurrentLoad) { |
| 104 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 105 EXPECT_FALSE(keep_alive_service_->is_keeping_alive()); |
| 106 |
| 107 StartLoadingProfile(profile1_.get()); |
| 108 loader_->InvalidatePendingProfileLoads(); |
| 109 // The profile is still considered loading even though we will do nothing when |
| 110 // it gets here. |
| 111 EXPECT_TRUE(loader_->IsAnyProfileLoading()); |
| 112 EXPECT_TRUE(keep_alive_service_->is_keeping_alive()); |
| 113 |
| 114 FinishLoadingProfile(profile1_.get()); |
| 115 EXPECT_EQ(NULL, last_callback_result_); |
| 116 } |
| OLD | NEW |