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

Side by Side Diff: chrome/browser/first_run/first_run_browsertest.cc

Issue 12670013: Out-of-process import on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: extract some more CLs Created 7 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h"
6 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/string_util.h"
7 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/component_loader.h" 11 #include "chrome/browser/extensions/component_loader.h"
10 #include "chrome/browser/first_run/first_run.h" 12 #include "chrome/browser/first_run/first_run.h"
11 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
16 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 59
58 IN_PROC_BROWSER_TEST_F(FirstRunBrowserTest, SetShouldShowWelcomePage) { 60 IN_PROC_BROWSER_TEST_F(FirstRunBrowserTest, SetShouldShowWelcomePage) {
59 EXPECT_FALSE(first_run::ShouldShowWelcomePage()); 61 EXPECT_FALSE(first_run::ShouldShowWelcomePage());
60 first_run::SetShouldShowWelcomePage(); 62 first_run::SetShouldShowWelcomePage();
61 EXPECT_TRUE(first_run::ShouldShowWelcomePage()); 63 EXPECT_TRUE(first_run::ShouldShowWelcomePage());
62 EXPECT_FALSE(first_run::ShouldShowWelcomePage()); 64 EXPECT_FALSE(first_run::ShouldShowWelcomePage());
63 } 65 }
64 66
65 #if !defined(OS_CHROMEOS) 67 #if !defined(OS_CHROMEOS)
66 namespace { 68 namespace {
67 class FirstRunIntegrationBrowserTest : public InProcessBrowserTest { 69
70 // A generic test class to be subclassed by test classes testing specific
71 // master_preferences. All subclasses must call SetMasterPreferencesForTest()
72 // from their SetUp() method before deferring the remainder of Setup() to this
73 // class.
74 class FirstRunMasterPrefsBrowserTestBase : public InProcessBrowserTest {
68 public: 75 public:
69 FirstRunIntegrationBrowserTest() {} 76 FirstRunMasterPrefsBrowserTestBase() {}
70 protected:
71 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
72 InProcessBrowserTest::SetUpCommandLine(command_line);
73 command_line->AppendSwitch(switches::kForceFirstRun);
74 EXPECT_FALSE(first_run::DidPerformProfileImport(NULL));
75
76 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting();
77
78 // The forked import process should run BrowserMain.
79 CommandLine import_arguments((CommandLine::NoProgram()));
80 import_arguments.AppendSwitch(content::kLaunchAsBrowser);
81 first_run::SetExtraArgumentsForImportProcess(import_arguments);
82 }
83 private:
84 DISALLOW_COPY_AND_ASSIGN(FirstRunIntegrationBrowserTest);
85 };
86
87 class FirstRunMasterPrefsBrowserTest : public FirstRunIntegrationBrowserTest {
88 public:
89 FirstRunMasterPrefsBrowserTest() {}
90 77
91 protected: 78 protected:
92 virtual void SetUp() OVERRIDE { 79 virtual void SetUp() OVERRIDE {
80 // All users of this test class need to call SetMasterPreferencesForTest()
81 // before this class' SetUp() is invoked.
82 ASSERT_TRUE(text_.get());
83
93 ASSERT_TRUE(file_util::CreateTemporaryFile(&prefs_file_)); 84 ASSERT_TRUE(file_util::CreateTemporaryFile(&prefs_file_));
94 // TODO(tapted): Make this reusable. 85 EXPECT_TRUE(file_util::WriteFile(prefs_file_, text_->c_str(),
gab 2013/04/18 21:51:18 Done via templates, see below :)!
tapted 2013/04/24 08:08:35 nice!
95 const char text[] = 86 text_->size()));
96 "{\n"
97 " \"distribution\": {\n"
98 " \"import_bookmarks\": false,\n"
99 " \"import_history\": false,\n"
100 " \"import_home_page\": false,\n"
101 " \"import_search_engine\": false\n"
102 " }\n"
103 "}\n";
104 EXPECT_TRUE(file_util::WriteFile(prefs_file_, text, strlen(text)));
105 first_run::SetMasterPrefsPathForTesting(prefs_file_); 87 first_run::SetMasterPrefsPathForTesting(prefs_file_);
106 88
107 // This invokes BrowserMain, and does the import, so must be done last. 89 // This invokes BrowserMain, and does the import, so must be done last.
108 FirstRunIntegrationBrowserTest::SetUp(); 90 InProcessBrowserTest::SetUp();
109 } 91 }
110 92
111 virtual void TearDown() OVERRIDE { 93 virtual void TearDown() OVERRIDE {
112 EXPECT_TRUE(file_util::Delete(prefs_file_, false)); 94 EXPECT_TRUE(file_util::Delete(prefs_file_, false));
113 FirstRunIntegrationBrowserTest::TearDown(); 95 InProcessBrowserTest::TearDown();
96 }
97
98 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
99 InProcessBrowserTest::SetUpCommandLine(command_line);
100 command_line->AppendSwitch(switches::kForceFirstRun);
101 EXPECT_EQ(first_run::AUTO_IMPORT_NONE, first_run::GetAutoImportState());
102
103 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting();
104 }
105
106 void SetMasterPreferencesForTest(const char text[]) {
107 text_.reset(new std::string(text));
tapted 2013/04/24 08:08:35 nit: indenting
gab 2013/04/24 20:24:59 Done.
114 } 108 }
115 109
116 private: 110 private:
117 base::FilePath prefs_file_; 111 base::FilePath prefs_file_;
112 scoped_ptr<std::string> text_;
118 113
119 DISALLOW_COPY_AND_ASSIGN(FirstRunMasterPrefsBrowserTest); 114 DISALLOW_COPY_AND_ASSIGN(FirstRunMasterPrefsBrowserTestBase);
120 }; 115 };
116
117 template<const char Text[]>
118 class FirstRunMasterPrefsBrowserTestT
119 : public FirstRunMasterPrefsBrowserTestBase {
120 public:
121 FirstRunMasterPrefsBrowserTestT() {}
122
123 protected:
124 virtual void SetUp() OVERRIDE {
125 SetMasterPreferencesForTest(Text);
126 FirstRunMasterPrefsBrowserTestBase::SetUp();
127 }
128
129 private:
130 DISALLOW_COPY_AND_ASSIGN(FirstRunMasterPrefsBrowserTestT);
131 };
132
121 } 133 }
tapted 2013/04/25 00:02:42 } // namespace (probably my bad from an earlier
gab 2013/04/25 18:50:00 Done.
122 134
123 // TODO(tapted): Investigate why this fails on Linux bots but does not 135 // TODO(tapted): Investigate why this fails on Linux bots but does not
124 // reproduce locally. See http://crbug.com/178062 . 136 // reproduce locally. See http://crbug.com/178062 .
125 // TODO(tapted): Investigate why this fails on mac_asan flakily 137 // TODO(tapted): Investigate why this fails on mac_asan flakily
126 // http://crbug.com/181499 . 138 // http://crbug.com/181499 .
127 #if defined(OS_LINUX) || (defined(OS_MACOSX) && defined(ADDRESS_SANITIZER)) 139 #if defined(OS_LINUX) || (defined(OS_MACOSX) && defined(ADDRESS_SANITIZER))
128 #define MAYBE_WaitForImport DISABLED_WaitForImport 140 #define MAYBE_ImportDefault DISABLED_ImportDefault
129 #else 141 #else
130 #define MAYBE_WaitForImport WaitForImport 142 #define MAYBE_ImportDefault ImportDefault
131 #endif 143 #endif
132 144
133 IN_PROC_BROWSER_TEST_F(FirstRunIntegrationBrowserTest, MAYBE_WaitForImport) { 145 extern const char kImportDefault[] =
tapted 2013/04/24 08:08:35 shouldn't be extern -- compiler will ignore an ext
gab 2013/04/24 20:24:59 If I don't make it extern, I get: error C2970: '`a
tapted 2013/04/25 00:02:42 Ah, drat. Where did I read that ~"static and anony
gab 2013/04/25 18:50:00 Feel free to try different things after this lands
134 bool success = false; 146 "{\n"
135 EXPECT_TRUE(first_run::DidPerformProfileImport(&success)); 147 "}\n";
148 typedef FirstRunMasterPrefsBrowserTestT<kImportDefault>
149 FirstRunMasterPrefsImportDefault;
150 IN_PROC_BROWSER_TEST_F(FirstRunMasterPrefsImportDefault, MAYBE_ImportDefault) {
151 int auto_import_state = first_run::GetAutoImportState();
136 // Aura builds skip over the import process. 152 // Aura builds skip over the import process.
137 #if defined(USE_AURA) 153 #if defined(USE_AURA)
138 EXPECT_FALSE(success); 154 EXPECT_EQ(first_run::AUTO_IMPORT_CALLED, auto_import_state);
139 #else 155 #else
140 EXPECT_TRUE(success); 156 EXPECT_EQ(first_run::AUTO_IMPORT_CALLED |
157 first_run::AUTO_IMPORT_PROFILE_IMPORTED,
158 auto_import_state);
159 #endif
160 }
161
tapted 2013/04/24 08:08:35 nit: extra vertical whitespace
gab 2013/04/24 20:24:59 Done.
162
163 // TODO(tapted): Investigate why this fails on Linux bots but does not
164 // reproduce locally. See http://crbug.com/178062 .
165 // TODO(tapted): Investigate why this fails on mac_asan flakily
166 // http://crbug.com/181499 .
167 #if defined(OS_LINUX) || (defined(OS_MACOSX) && defined(ADDRESS_SANITIZER))
168 #define MAYBE_ImportBookmarksFile DISABLED_ImportBookmarksFile
169 #else
170 #define MAYBE_ImportBookmarksFile ImportBookmarksFile
171 #endif
172
173 extern const char kImportBookmarksFile[] =
174 "{\n"
175 " \"distribution\": {\n"
176 " \"import_bookmarks_from_file\": \"/foo/doesntexists.wtv\"\n"
177 " }\n"
178 "}\n";
179 typedef FirstRunMasterPrefsBrowserTestT<kImportBookmarksFile>
180 FirstRunMasterPrefsImportBookmarksFile;
181 IN_PROC_BROWSER_TEST_F(FirstRunMasterPrefsImportBookmarksFile,
182 MAYBE_ImportBookmarksFile) {
183 int auto_import_state = first_run::GetAutoImportState();
184 // Aura builds skip over the import process.
185 #if defined(USE_AURA)
186 EXPECT_EQ(first_run::AUTO_IMPORT_CALLED, auto_import_state);
187 #else
188 EXPECT_EQ(first_run::AUTO_IMPORT_CALLED |
189 first_run::AUTO_IMPORT_PROFILE_IMPORTED |
190 first_run::AUTO_IMPORT_BOOKMARKS_FILE_IMPORTED,
191 auto_import_state);
141 #endif 192 #endif
142 } 193 }
143 194
144 // Test an import with all import options disabled. This is a regression test 195 // Test an import with all import options disabled. This is a regression test
145 // for http://crbug.com/169984 where this would cause the import process to 196 // for http://crbug.com/169984 where this would cause the import process to
146 // stay running, and the NTP to be loaded with no apps. 197 // stay running, and the NTP to be loaded with no apps.
147 IN_PROC_BROWSER_TEST_F(FirstRunMasterPrefsBrowserTest, 198 // The file doesn't actually need to exist for this integration test to trigger
tapted 2013/04/24 08:08:35 Could it be picking up '/Library/Google Chrome Mas
gab 2013/04/24 20:24:59 This comment belonged with the ImportBookmarksFile
tapted 2013/04/25 00:02:42 Ah. Cool.
199 // the interaction being tested.
200 extern const char kImportNothing[] =
201 "{\n"
202 " \"distribution\": {\n"
203 " \"import_bookmarks\": false,\n"
204 " \"import_history\": false,\n"
205 " \"import_home_page\": false,\n"
206 " \"import_search_engine\": false\n"
207 " }\n"
208 "}\n";
209 typedef FirstRunMasterPrefsBrowserTestT<kImportNothing>
210 FirstRunMasterPrefsImportNothing;
211 IN_PROC_BROWSER_TEST_F(FirstRunMasterPrefsImportNothing,
148 ImportNothingAndShowNewTabPage) { 212 ImportNothingAndShowNewTabPage) {
149 EXPECT_TRUE(first_run::DidPerformProfileImport(NULL)); 213 EXPECT_EQ(first_run::AUTO_IMPORT_CALLED, first_run::GetAutoImportState());
150 ui_test_utils::NavigateToURLWithDisposition( 214 ui_test_utils::NavigateToURLWithDisposition(
151 browser(), GURL(chrome::kChromeUINewTabURL), CURRENT_TAB, 215 browser(), GURL(chrome::kChromeUINewTabURL), CURRENT_TAB,
152 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 216 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
153 content::WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(0); 217 content::WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(0);
154 EXPECT_EQ(1, tab->GetMaxPageID()); 218 EXPECT_EQ(1, tab->GetMaxPageID());
155 } 219 }
156 220
157 #endif // !defined(OS_CHROMEOS) 221 #endif // !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698