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

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

Issue 15968002: Revert 201837 "OOP import on Windows." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 7 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"
7 #include "base/prefs/pref_service.h" 6 #include "base/prefs/pref_service.h"
8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/extensions/component_loader.h" 9 #include "chrome/browser/extensions/component_loader.h"
12 #include "chrome/browser/first_run/first_run.h" 10 #include "chrome/browser/first_run/first_run.h"
13 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
18 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 57
60 IN_PROC_BROWSER_TEST_F(FirstRunBrowserTest, SetShouldShowWelcomePage) { 58 IN_PROC_BROWSER_TEST_F(FirstRunBrowserTest, SetShouldShowWelcomePage) {
61 EXPECT_FALSE(first_run::ShouldShowWelcomePage()); 59 EXPECT_FALSE(first_run::ShouldShowWelcomePage());
62 first_run::SetShouldShowWelcomePage(); 60 first_run::SetShouldShowWelcomePage();
63 EXPECT_TRUE(first_run::ShouldShowWelcomePage()); 61 EXPECT_TRUE(first_run::ShouldShowWelcomePage());
64 EXPECT_FALSE(first_run::ShouldShowWelcomePage()); 62 EXPECT_FALSE(first_run::ShouldShowWelcomePage());
65 } 63 }
66 64
67 #if !defined(OS_CHROMEOS) 65 #if !defined(OS_CHROMEOS)
68 namespace { 66 namespace {
67 class FirstRunIntegrationBrowserTest : public InProcessBrowserTest {
68 public:
69 FirstRunIntegrationBrowserTest() {}
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));
69 75
70 // A generic test class to be subclassed by test classes testing specific 76 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting();
71 // master_preferences. All subclasses must call SetMasterPreferencesForTest() 77
72 // from their SetUp() method before deferring the remainder of Setup() to this 78 // The forked import process should run BrowserMain.
73 // class. 79 CommandLine import_arguments((CommandLine::NoProgram()));
74 class FirstRunMasterPrefsBrowserTestBase : public InProcessBrowserTest { 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 {
75 public: 88 public:
76 FirstRunMasterPrefsBrowserTestBase() {} 89 FirstRunMasterPrefsBrowserTest() {}
77 90
78 protected: 91 protected:
79 virtual void SetUp() OVERRIDE { 92 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
84 ASSERT_TRUE(file_util::CreateTemporaryFile(&prefs_file_)); 93 ASSERT_TRUE(file_util::CreateTemporaryFile(&prefs_file_));
85 EXPECT_TRUE(file_util::WriteFile(prefs_file_, text_->c_str(), 94 // TODO(tapted): Make this reusable.
86 text_->size())); 95 const char text[] =
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)));
87 first_run::SetMasterPrefsPathForTesting(prefs_file_); 105 first_run::SetMasterPrefsPathForTesting(prefs_file_);
88 106
89 // This invokes BrowserMain, and does the import, so must be done last. 107 // This invokes BrowserMain, and does the import, so must be done last.
90 InProcessBrowserTest::SetUp(); 108 FirstRunIntegrationBrowserTest::SetUp();
91 } 109 }
92 110
93 virtual void TearDown() OVERRIDE { 111 virtual void TearDown() OVERRIDE {
94 EXPECT_TRUE(file_util::Delete(prefs_file_, false)); 112 EXPECT_TRUE(file_util::Delete(prefs_file_, false));
95 InProcessBrowserTest::TearDown(); 113 FirstRunIntegrationBrowserTest::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::auto_import_state());
102
103 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting();
104 }
105
106 void SetMasterPreferencesForTest(const char text[]) {
107 text_.reset(new std::string(text));
108 } 114 }
109 115
110 private: 116 private:
111 base::FilePath prefs_file_; 117 base::FilePath prefs_file_;
112 scoped_ptr<std::string> text_;
113 118
114 DISALLOW_COPY_AND_ASSIGN(FirstRunMasterPrefsBrowserTestBase); 119 DISALLOW_COPY_AND_ASSIGN(FirstRunMasterPrefsBrowserTest);
115 }; 120 };
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
133 } // namespace
134
135 // TODO(tapted): Investigate why this fails on Linux bots but does not
136 // reproduce locally. See http://crbug.com/178062 .
137 // TODO(tapted): Investigate why this fails on mac_asan flakily
138 // http://crbug.com/181499 .
139 #if defined(OS_LINUX) || (defined(OS_MACOSX) && defined(ADDRESS_SANITIZER))
140 #define MAYBE_ImportDefault DISABLED_ImportDefault
141 #else
142 #define MAYBE_ImportDefault ImportDefault
143 #endif
144
145 extern const char kImportDefault[] =
146 "{\n"
147 "}\n";
148 typedef FirstRunMasterPrefsBrowserTestT<kImportDefault>
149 FirstRunMasterPrefsImportDefault;
150 IN_PROC_BROWSER_TEST_F(FirstRunMasterPrefsImportDefault, MAYBE_ImportDefault) {
151 int auto_import_state = first_run::auto_import_state();
152 // Aura builds skip over the import process.
153 #if defined(USE_AURA)
154 EXPECT_EQ(first_run::AUTO_IMPORT_CALLED, auto_import_state);
155 #else
156 EXPECT_EQ(first_run::AUTO_IMPORT_CALLED |
157 first_run::AUTO_IMPORT_PROFILE_IMPORTED,
158 auto_import_state);
159 #endif
160 } 121 }
161 122
162 // TODO(tapted): Investigate why this fails on Linux bots but does not 123 // TODO(tapted): Investigate why this fails on Linux bots but does not
163 // reproduce locally. See http://crbug.com/178062 . 124 // reproduce locally. See http://crbug.com/178062 .
164 // TODO(tapted): Investigate why this fails on mac_asan flakily 125 // TODO(tapted): Investigate why this fails on mac_asan flakily
165 // http://crbug.com/181499 . 126 // http://crbug.com/181499 .
166 #if defined(OS_LINUX) || (defined(OS_MACOSX) && defined(ADDRESS_SANITIZER)) 127 #if defined(OS_LINUX) || (defined(OS_MACOSX) && defined(ADDRESS_SANITIZER))
167 #define MAYBE_ImportBookmarksFile DISABLED_ImportBookmarksFile 128 #define MAYBE_WaitForImport DISABLED_WaitForImport
168 #else 129 #else
169 #define MAYBE_ImportBookmarksFile ImportBookmarksFile 130 #define MAYBE_WaitForImport WaitForImport
170 #endif 131 #endif
171 132
172 // The bookmarks file doesn't actually need to exist for this integration test 133 IN_PROC_BROWSER_TEST_F(FirstRunIntegrationBrowserTest, MAYBE_WaitForImport) {
173 // to trigger the interaction being tested. 134 bool success = false;
174 extern const char kImportBookmarksFile[] = 135 EXPECT_TRUE(first_run::DidPerformProfileImport(&success));
175 "{\n"
176 " \"distribution\": {\n"
177 " \"import_bookmarks_from_file\": \"/foo/doesntexists.wtv\"\n"
178 " }\n"
179 "}\n";
180 typedef FirstRunMasterPrefsBrowserTestT<kImportBookmarksFile>
181 FirstRunMasterPrefsImportBookmarksFile;
182 IN_PROC_BROWSER_TEST_F(FirstRunMasterPrefsImportBookmarksFile,
183 MAYBE_ImportBookmarksFile) {
184 int auto_import_state = first_run::auto_import_state();
185 // Aura builds skip over the import process. 136 // Aura builds skip over the import process.
186 #if defined(USE_AURA) 137 #if defined(USE_AURA)
187 EXPECT_EQ(first_run::AUTO_IMPORT_CALLED, auto_import_state); 138 EXPECT_FALSE(success);
188 #else 139 #else
189 EXPECT_EQ(first_run::AUTO_IMPORT_CALLED | 140 EXPECT_TRUE(success);
190 first_run::AUTO_IMPORT_PROFILE_IMPORTED |
191 first_run::AUTO_IMPORT_BOOKMARKS_FILE_IMPORTED,
192 auto_import_state);
193 #endif 141 #endif
194 } 142 }
195 143
196 // Test an import with all import options disabled. This is a regression test 144 // Test an import with all import options disabled. This is a regression test
197 // for http://crbug.com/169984 where this would cause the import process to 145 // for http://crbug.com/169984 where this would cause the import process to
198 // stay running, and the NTP to be loaded with no apps. 146 // stay running, and the NTP to be loaded with no apps.
199 extern const char kImportNothing[] = 147 IN_PROC_BROWSER_TEST_F(FirstRunMasterPrefsBrowserTest,
200 "{\n"
201 " \"distribution\": {\n"
202 " \"import_bookmarks\": false,\n"
203 " \"import_history\": false,\n"
204 " \"import_home_page\": false,\n"
205 " \"import_search_engine\": false\n"
206 " }\n"
207 "}\n";
208 typedef FirstRunMasterPrefsBrowserTestT<kImportNothing>
209 FirstRunMasterPrefsImportNothing;
210 IN_PROC_BROWSER_TEST_F(FirstRunMasterPrefsImportNothing,
211 ImportNothingAndShowNewTabPage) { 148 ImportNothingAndShowNewTabPage) {
212 EXPECT_EQ(first_run::AUTO_IMPORT_CALLED, first_run::auto_import_state()); 149 EXPECT_TRUE(first_run::DidPerformProfileImport(NULL));
213 ui_test_utils::NavigateToURLWithDisposition( 150 ui_test_utils::NavigateToURLWithDisposition(
214 browser(), GURL(chrome::kChromeUINewTabURL), CURRENT_TAB, 151 browser(), GURL(chrome::kChromeUINewTabURL), CURRENT_TAB,
215 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 152 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
216 content::WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(0); 153 content::WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(0);
217 EXPECT_EQ(1, tab->GetMaxPageID()); 154 EXPECT_EQ(1, tab->GetMaxPageID());
218 } 155 }
219 156
220 #endif // !defined(OS_CHROMEOS) 157 #endif // !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/first_run/first_run.cc ('k') | trunk/src/chrome/browser/first_run/first_run_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698