Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / app_list / profile_loader_unittest.cc
blobb709ca84bb070c7c056a0e33b062b2b5b5172a4a
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.
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_profile.h"
11 #include "chrome/browser/ui/app_list/test/fake_profile_store.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 class ProfileLoaderUnittest : public testing::Test {
15 public:
16 void SetUp() override {
17 last_callback_result_ = NULL;
18 profile1_.reset(
19 new FakeProfile("p1", base::FilePath(FILE_PATH_LITERAL("profile1"))));
20 profile2_.reset(
21 new FakeProfile("p2", base::FilePath(FILE_PATH_LITERAL("profile2"))));
23 profile_store_.reset(new FakeProfileStore(
24 base::FilePath(FILE_PATH_LITERAL("udd")), nullptr));
25 loader_.reset(new ProfileLoader(profile_store_.get()));
28 void StartLoadingProfile(Profile* profile) {
29 loader_->LoadProfileInvalidatingOtherLoads(
30 profile->GetPath(),
31 base::Bind(&ProfileLoaderUnittest::OnProfileLoaded,
32 base::Unretained(this)));
35 void FinishLoadingProfile(Profile* profile) {
36 profile_store_->LoadProfile(profile);
39 void OnProfileLoaded(Profile* profile) {
40 last_callback_result_ = profile;
43 bool HasKeepAlive() const {
44 return loader_->keep_alive_.get() != NULL;
47 protected:
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_;
55 TEST_F(ProfileLoaderUnittest, LoadASecondProfileBeforeTheFirstFinishes) {
56 EXPECT_FALSE(loader_->IsAnyProfileLoading());
58 StartLoadingProfile(profile1_.get());
59 EXPECT_TRUE(loader_->IsAnyProfileLoading());
61 StartLoadingProfile(profile2_.get());
62 FinishLoadingProfile(profile1_.get());
63 EXPECT_EQ(NULL, last_callback_result_);
65 FinishLoadingProfile(profile2_.get());
66 EXPECT_EQ(profile2_.get(), last_callback_result_);
67 EXPECT_FALSE(loader_->IsAnyProfileLoading());
70 TEST_F(ProfileLoaderUnittest, TestKeepsAliveWhileLoadingProfiles) {
71 EXPECT_FALSE(loader_->IsAnyProfileLoading());
72 EXPECT_FALSE(HasKeepAlive());
74 StartLoadingProfile(profile1_.get());
75 EXPECT_TRUE(loader_->IsAnyProfileLoading());
76 EXPECT_TRUE(HasKeepAlive());
78 FinishLoadingProfile(profile1_.get());
79 EXPECT_FALSE(loader_->IsAnyProfileLoading());
80 EXPECT_FALSE(HasKeepAlive());
83 TEST_F(ProfileLoaderUnittest, TestKeepsAliveWhileLoadingMultipleProfiles) {
84 EXPECT_FALSE(loader_->IsAnyProfileLoading());
85 EXPECT_FALSE(HasKeepAlive());
87 StartLoadingProfile(profile1_.get());
88 EXPECT_TRUE(loader_->IsAnyProfileLoading());
89 EXPECT_TRUE(HasKeepAlive());
91 StartLoadingProfile(profile2_.get());
92 EXPECT_TRUE(loader_->IsAnyProfileLoading());
93 EXPECT_TRUE(HasKeepAlive());
95 FinishLoadingProfile(profile1_.get());
96 EXPECT_TRUE(loader_->IsAnyProfileLoading());
97 EXPECT_TRUE(HasKeepAlive());
99 FinishLoadingProfile(profile2_.get());
100 EXPECT_FALSE(loader_->IsAnyProfileLoading());
101 EXPECT_FALSE(HasKeepAlive());
104 TEST_F(ProfileLoaderUnittest, TestInvalidatingCurrentLoad) {
105 EXPECT_FALSE(loader_->IsAnyProfileLoading());
106 EXPECT_FALSE(HasKeepAlive());
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(HasKeepAlive());
115 FinishLoadingProfile(profile1_.get());
116 EXPECT_EQ(NULL, last_callback_result_);