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

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

Issue 23551005: Revert 219709 "Remove the Extensions URLRequestContext." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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"
16 #include "chrome/test/base/testing_profile.h" 15 #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"
19 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 17 #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)
27 18
28 namespace { 19 namespace {
29 20
30 using ::testing::_; 21 using ::testing::_;
31 using ::testing::Invoke; 22 using ::testing::Invoke;
32 using ::testing::Return; 23 using ::testing::Return;
33 using ::testing::StrictMock; 24 using ::testing::StrictMock;
34 using ::testing::WithArgs; 25 using ::testing::WithArgs;
35 26
36 class TestProfileLoader : public ProfileLoader { 27 class TestProfileLoader : public ProfileLoader {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 friend class base::RefCountedThreadSafe<MockCallback>; 62 friend class base::RefCountedThreadSafe<MockCallback>;
72 virtual ~MockCallback(); 63 virtual ~MockCallback();
73 64
74 private: 65 private:
75 DISALLOW_COPY_AND_ASSIGN(MockCallback); 66 DISALLOW_COPY_AND_ASSIGN(MockCallback);
76 }; 67 };
77 68
78 MockCallback::MockCallback() {} 69 MockCallback::MockCallback() {}
79 MockCallback::~MockCallback() {} 70 MockCallback::~MockCallback() {}
80 71
81 class ProfileLoaderTest : public testing::Test { 72 TEST(ProfileLoaderTest, LoadProfileInvalidatingOtherLoads) {
82 protected: 73 TestingProfile profile;
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");
105 base::FilePath fake_profile_path_1 = 74 base::FilePath fake_profile_path_1 =
106 base::FilePath::FromUTF8Unsafe("fake/profile 1"); 75 base::FilePath::FromUTF8Unsafe("fake/profile 1");
107 base::FilePath fake_profile_path_2 = 76 base::FilePath fake_profile_path_2 =
108 base::FilePath::FromUTF8Unsafe("fake/profile 2"); 77 base::FilePath::FromUTF8Unsafe("fake/profile 2");
109 78
110 TestProfileLoader loader; 79 TestProfileLoader loader;
111 EXPECT_FALSE(loader.IsAnyProfileLoading()); 80 EXPECT_FALSE(loader.IsAnyProfileLoading());
112 81
113 // path_1 never loads. 82 // path_1 never loads.
114 EXPECT_CALL(loader, GetProfileByPath(fake_profile_path_1)) 83 EXPECT_CALL(loader, GetProfileByPath(fake_profile_path_1))
115 .WillRepeatedly(Return(static_cast<Profile*>(NULL))); 84 .WillRepeatedly(Return(static_cast<Profile*>(NULL)));
116 EXPECT_CALL(loader, 85 EXPECT_CALL(loader,
117 CreateProfileAsync(fake_profile_path_1, _, _, _, std::string())) 86 CreateProfileAsync(fake_profile_path_1, _, _, _, std::string()))
118 .WillRepeatedly(WithArgs<0, 1>( 87 .WillRepeatedly(WithArgs<0, 1>(
119 Invoke(&loader, &TestProfileLoader::SetCreateCallback))); 88 Invoke(&loader, &TestProfileLoader::SetCreateCallback)));
120 89
121 // path_2 loads after the first request. 90 // path_2 loads after the first request.
122 EXPECT_CALL(loader, GetProfileByPath(fake_profile_path_2)) 91 EXPECT_CALL(loader, GetProfileByPath(fake_profile_path_2))
123 .WillOnce(Return(static_cast<Profile*>(NULL))) 92 .WillOnce(Return(static_cast<Profile*>(NULL)))
124 .WillRepeatedly(Return(profile)); 93 .WillRepeatedly(Return(&profile));
125 EXPECT_CALL(loader, 94 EXPECT_CALL(loader,
126 CreateProfileAsync(fake_profile_path_2, _, _, _, std::string())) 95 CreateProfileAsync(fake_profile_path_2, _, _, _, std::string()))
127 .WillRepeatedly(WithArgs<0, 1>( 96 .WillRepeatedly(WithArgs<0, 1>(
128 Invoke(&loader, &TestProfileLoader::SetCreateCallback))); 97 Invoke(&loader, &TestProfileLoader::SetCreateCallback)));
129 98
130 // Try to load both paths twice. 99 // Try to load both paths twice.
131 // path_1_load is never called because it is first invalidated by the load 100 // path_1_load is never called because it is first invalidated by the load
132 // request for (path_2), and then invalidated manually. 101 // request for (path_2), and then invalidated manually.
133 // path_2_load is called both times. 102 // path_2_load is called both times.
134 StrictMock<MockCallback>* path_1_load = new StrictMock<MockCallback>(); 103 StrictMock<MockCallback>* path_1_load = new StrictMock<MockCallback>();
135 StrictMock<MockCallback>* path_2_load = new StrictMock<MockCallback>(); 104 StrictMock<MockCallback>* path_2_load = new StrictMock<MockCallback>();
136 EXPECT_CALL(*path_2_load, Run(profile)) 105 EXPECT_CALL(*path_2_load, Run(&profile))
137 .Times(2); 106 .Times(2);
138 107
139 // Try to load path_1. 108 // Try to load path_1.
140 loader.LoadProfileInvalidatingOtherLoads( 109 loader.LoadProfileInvalidatingOtherLoads(
141 fake_profile_path_1, base::Bind(&MockCallback::Run, path_1_load)); 110 fake_profile_path_1, base::Bind(&MockCallback::Run, path_1_load));
142 EXPECT_TRUE(loader.IsAnyProfileLoading()); 111 EXPECT_TRUE(loader.IsAnyProfileLoading());
143 112
144 // Try to load path_2, this invalidates the previous request. 113 // Try to load path_2, this invalidates the previous request.
145 loader.LoadProfileInvalidatingOtherLoads( 114 loader.LoadProfileInvalidatingOtherLoads(
146 fake_profile_path_2, base::Bind(&MockCallback::Run, path_2_load)); 115 fake_profile_path_2, base::Bind(&MockCallback::Run, path_2_load));
147 116
148 // Finish the load request for path_1, then for path_2. 117 // Finish the load request for path_1, then for path_2.
149 loader.RunCreateCallback(fake_profile_path_1, profile, 118 loader.RunCreateCallback(fake_profile_path_1, &profile,
150 Profile::CREATE_STATUS_INITIALIZED); 119 Profile::CREATE_STATUS_INITIALIZED);
151 loader.RunCreateCallback(fake_profile_path_2, profile, 120 loader.RunCreateCallback(fake_profile_path_2, &profile,
152 Profile::CREATE_STATUS_INITIALIZED); 121 Profile::CREATE_STATUS_INITIALIZED);
153 EXPECT_FALSE(loader.IsAnyProfileLoading()); 122 EXPECT_FALSE(loader.IsAnyProfileLoading());
154 123
155 // The second request for path_2 should return immediately. 124 // The second request for path_2 should return immediately.
156 loader.LoadProfileInvalidatingOtherLoads( 125 loader.LoadProfileInvalidatingOtherLoads(
157 fake_profile_path_2, base::Bind(&MockCallback::Run, path_2_load)); 126 fake_profile_path_2, base::Bind(&MockCallback::Run, path_2_load));
158 127
159 // Make a second request for path_1, and invalidate it. 128 // Make a second request for path_1, and invalidate it.
160 loader.LoadProfileInvalidatingOtherLoads( 129 loader.LoadProfileInvalidatingOtherLoads(
161 fake_profile_path_1, base::Bind(&MockCallback::Run, path_1_load)); 130 fake_profile_path_1, base::Bind(&MockCallback::Run, path_1_load));
162 loader.InvalidatePendingProfileLoads(); 131 loader.InvalidatePendingProfileLoads();
163 } 132 }
164 133
165 } // namespace 134 } // namespace
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/profiles/profile_io_data.cc ('k') | trunk/src/chrome/browser/safe_browsing/safe_browsing_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698