| 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 virtual void TearDown() OVERRIDE { |
| 32 } |
| 33 |
| 34 void OnProfileLoaded(Profile* profile) { |
| 35 last_callback_result_ = profile; |
| 36 } |
| 37 |
| 38 FakeKeepAliveService* keep_alive_service_; |
| 39 scoped_ptr<ProfileLoader> loader_; |
| 40 scoped_ptr<FakeProfileStore> profile_store_; |
| 41 scoped_ptr<FakeProfile> profile1_; |
| 42 scoped_ptr<FakeProfile> profile2_; |
| 43 Profile* last_callback_result_; |
| 44 }; |
| 45 |
| 46 TEST_F(ProfileLoaderUnittest, LoadASecondProfileBeforeTheFirstFinishes) { |
| 47 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 48 |
| 49 loader_->LoadProfileInvalidatingOtherLoads( |
| 50 profile1_->GetPath(), |
| 51 base::Bind(&ProfileLoaderUnittest::OnProfileLoaded, |
| 52 base::Unretained(this))); |
| 53 EXPECT_TRUE(loader_->IsAnyProfileLoading()); |
| 54 loader_->LoadProfileInvalidatingOtherLoads( |
| 55 profile2_->GetPath(), |
| 56 base::Bind(&ProfileLoaderUnittest::OnProfileLoaded, |
| 57 base::Unretained(this))); |
| 58 |
| 59 profile_store_->RunCallbackByPath(profile1_->GetPath(), profile1_.get()); |
| 60 EXPECT_EQ(NULL, last_callback_result_); |
| 61 |
| 62 profile_store_->RunCallbackByPath(profile2_->GetPath(), profile2_.get()); |
| 63 EXPECT_EQ(profile2_.get(), last_callback_result_); |
| 64 |
| 65 EXPECT_FALSE(loader_->IsAnyProfileLoading()); |
| 66 } |
| OLD | NEW |