Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: chrome/browser/profiles/profile_loader_unittest.cc

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android webview init fix merged in. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/profiles/profile_loader.h" 5 #include "chrome/browser/profiles/profile_loader.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/lifetime/application_lifetime.h" 12 #include "chrome/browser/lifetime/application_lifetime.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_loader.h" 14 #include "chrome/browser/profiles/profile_loader.h"
15 #include "chrome/test/base/testing_browser_process.h"
15 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "chrome/test/base/testing_profile_manager.h"
18 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/message_center/message_center.h"
22
23 #if defined(OS_CHROMEOS)
24 #include "base/command_line.h"
25 #include "chrome/common/chrome_switches.h"
26 #endif // defined(OS_CHROMEOS)
18 27
19 namespace { 28 namespace {
20 29
21 using ::testing::_; 30 using ::testing::_;
22 using ::testing::Invoke; 31 using ::testing::Invoke;
23 using ::testing::Return; 32 using ::testing::Return;
24 using ::testing::StrictMock; 33 using ::testing::StrictMock;
25 using ::testing::WithArgs; 34 using ::testing::WithArgs;
26 35
27 class TestProfileLoader : public ProfileLoader { 36 class TestProfileLoader : public ProfileLoader {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 friend class base::RefCountedThreadSafe<MockCallback>; 71 friend class base::RefCountedThreadSafe<MockCallback>;
63 virtual ~MockCallback(); 72 virtual ~MockCallback();
64 73
65 private: 74 private:
66 DISALLOW_COPY_AND_ASSIGN(MockCallback); 75 DISALLOW_COPY_AND_ASSIGN(MockCallback);
67 }; 76 };
68 77
69 MockCallback::MockCallback() {} 78 MockCallback::MockCallback() {}
70 MockCallback::~MockCallback() {} 79 MockCallback::~MockCallback() {}
71 80
72 TEST(ProfileLoaderTest, LoadProfileInvalidatingOtherLoads) { 81 class ProfileLoaderTest : public testing::Test {
73 TestingProfile profile; 82 protected:
83 static void SetUpTestCase() {
84 #if defined(OS_CHROMEOS)
85 // Needed to handle http://crbug.com/119175.
86 CommandLine::ForCurrentProcess()->AppendSwitch(
87 switches::kDisableZeroBrowsersOpenForTests);
88 #endif // defined(OS_CHROMEOS)
89 message_center::MessageCenter::Initialize();
90 }
91
92 static void TearDownTestCase() {
93 message_center::MessageCenter::Shutdown();
94 }
95
96 private:
97 content::TestBrowserThreadBundle thread_bundle_;
98 };
99
100 TEST_F(ProfileLoaderTest, LoadProfileInvalidatingOtherLoads) {
101 TestingProfileManager profile_manager(TestingBrowserProcess::GetGlobal());
102 ASSERT_TRUE(profile_manager.SetUp());
103 TestingProfile* profile =
104 profile_manager.CreateTestingProfile("TestProfile");
74 base::FilePath fake_profile_path_1 = 105 base::FilePath fake_profile_path_1 =
75 base::FilePath::FromUTF8Unsafe("fake/profile 1"); 106 base::FilePath::FromUTF8Unsafe("fake/profile 1");
76 base::FilePath fake_profile_path_2 = 107 base::FilePath fake_profile_path_2 =
77 base::FilePath::FromUTF8Unsafe("fake/profile 2"); 108 base::FilePath::FromUTF8Unsafe("fake/profile 2");
78 109
79 TestProfileLoader loader; 110 TestProfileLoader loader;
80 EXPECT_FALSE(loader.IsAnyProfileLoading()); 111 EXPECT_FALSE(loader.IsAnyProfileLoading());
81 112
82 // path_1 never loads. 113 // path_1 never loads.
83 EXPECT_CALL(loader, GetProfileByPath(fake_profile_path_1)) 114 EXPECT_CALL(loader, GetProfileByPath(fake_profile_path_1))
84 .WillRepeatedly(Return(static_cast<Profile*>(NULL))); 115 .WillRepeatedly(Return(static_cast<Profile*>(NULL)));
85 EXPECT_CALL(loader, 116 EXPECT_CALL(loader,
86 CreateProfileAsync(fake_profile_path_1, _, _, _, std::string())) 117 CreateProfileAsync(fake_profile_path_1, _, _, _, std::string()))
87 .WillRepeatedly(WithArgs<0, 1>( 118 .WillRepeatedly(WithArgs<0, 1>(
88 Invoke(&loader, &TestProfileLoader::SetCreateCallback))); 119 Invoke(&loader, &TestProfileLoader::SetCreateCallback)));
89 120
90 // path_2 loads after the first request. 121 // path_2 loads after the first request.
91 EXPECT_CALL(loader, GetProfileByPath(fake_profile_path_2)) 122 EXPECT_CALL(loader, GetProfileByPath(fake_profile_path_2))
92 .WillOnce(Return(static_cast<Profile*>(NULL))) 123 .WillOnce(Return(static_cast<Profile*>(NULL)))
93 .WillRepeatedly(Return(&profile)); 124 .WillRepeatedly(Return(profile));
94 EXPECT_CALL(loader, 125 EXPECT_CALL(loader,
95 CreateProfileAsync(fake_profile_path_2, _, _, _, std::string())) 126 CreateProfileAsync(fake_profile_path_2, _, _, _, std::string()))
96 .WillRepeatedly(WithArgs<0, 1>( 127 .WillRepeatedly(WithArgs<0, 1>(
97 Invoke(&loader, &TestProfileLoader::SetCreateCallback))); 128 Invoke(&loader, &TestProfileLoader::SetCreateCallback)));
98 129
99 // Try to load both paths twice. 130 // Try to load both paths twice.
100 // path_1_load is never called because it is first invalidated by the load 131 // path_1_load is never called because it is first invalidated by the load
101 // request for (path_2), and then invalidated manually. 132 // request for (path_2), and then invalidated manually.
102 // path_2_load is called both times. 133 // path_2_load is called both times.
103 StrictMock<MockCallback>* path_1_load = new StrictMock<MockCallback>(); 134 StrictMock<MockCallback>* path_1_load = new StrictMock<MockCallback>();
104 StrictMock<MockCallback>* path_2_load = new StrictMock<MockCallback>(); 135 StrictMock<MockCallback>* path_2_load = new StrictMock<MockCallback>();
105 EXPECT_CALL(*path_2_load, Run(&profile)) 136 EXPECT_CALL(*path_2_load, Run(profile))
106 .Times(2); 137 .Times(2);
107 138
108 // Try to load path_1. 139 // Try to load path_1.
109 loader.LoadProfileInvalidatingOtherLoads( 140 loader.LoadProfileInvalidatingOtherLoads(
110 fake_profile_path_1, base::Bind(&MockCallback::Run, path_1_load)); 141 fake_profile_path_1, base::Bind(&MockCallback::Run, path_1_load));
111 EXPECT_TRUE(loader.IsAnyProfileLoading()); 142 EXPECT_TRUE(loader.IsAnyProfileLoading());
112 143
113 // Try to load path_2, this invalidates the previous request. 144 // Try to load path_2, this invalidates the previous request.
114 loader.LoadProfileInvalidatingOtherLoads( 145 loader.LoadProfileInvalidatingOtherLoads(
115 fake_profile_path_2, base::Bind(&MockCallback::Run, path_2_load)); 146 fake_profile_path_2, base::Bind(&MockCallback::Run, path_2_load));
116 147
117 // Finish the load request for path_1, then for path_2. 148 // Finish the load request for path_1, then for path_2.
118 loader.RunCreateCallback(fake_profile_path_1, &profile, 149 loader.RunCreateCallback(fake_profile_path_1, profile,
119 Profile::CREATE_STATUS_INITIALIZED); 150 Profile::CREATE_STATUS_INITIALIZED);
120 loader.RunCreateCallback(fake_profile_path_2, &profile, 151 loader.RunCreateCallback(fake_profile_path_2, profile,
121 Profile::CREATE_STATUS_INITIALIZED); 152 Profile::CREATE_STATUS_INITIALIZED);
122 EXPECT_FALSE(loader.IsAnyProfileLoading()); 153 EXPECT_FALSE(loader.IsAnyProfileLoading());
123 154
124 // The second request for path_2 should return immediately. 155 // The second request for path_2 should return immediately.
125 loader.LoadProfileInvalidatingOtherLoads( 156 loader.LoadProfileInvalidatingOtherLoads(
126 fake_profile_path_2, base::Bind(&MockCallback::Run, path_2_load)); 157 fake_profile_path_2, base::Bind(&MockCallback::Run, path_2_load));
127 158
128 // Make a second request for path_1, and invalidate it. 159 // Make a second request for path_1, and invalidate it.
129 loader.LoadProfileInvalidatingOtherLoads( 160 loader.LoadProfileInvalidatingOtherLoads(
130 fake_profile_path_1, base::Bind(&MockCallback::Run, path_1_load)); 161 fake_profile_path_1, base::Bind(&MockCallback::Run, path_1_load));
131 loader.InvalidatePendingProfileLoads(); 162 loader.InvalidatePendingProfileLoads();
132 } 163 }
133 164
134 } // namespace 165 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_io_data.cc ('k') | chrome/browser/safe_browsing/safe_browsing_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698