OLD | NEW |
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 Loading... |
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(), |
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::auto_import_state()); |
| 102 |
| 103 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); |
| 104 } |
| 105 |
| 106 void SetMasterPreferencesForTest(const char text[]) { |
| 107 text_.reset(new std::string(text)); |
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 |
| 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 |
121 } | 160 } |
122 | 161 |
123 // TODO(tapted): Investigate why this fails on Linux bots but does not | 162 // TODO(tapted): Investigate why this fails on Linux bots but does not |
124 // reproduce locally. See http://crbug.com/178062 . | 163 // reproduce locally. See http://crbug.com/178062 . |
125 // TODO(tapted): Investigate why this fails on mac_asan flakily | 164 // TODO(tapted): Investigate why this fails on mac_asan flakily |
126 // http://crbug.com/181499 . | 165 // http://crbug.com/181499 . |
127 #if defined(OS_LINUX) || (defined(OS_MACOSX) && defined(ADDRESS_SANITIZER)) | 166 #if defined(OS_LINUX) || (defined(OS_MACOSX) && defined(ADDRESS_SANITIZER)) |
128 #define MAYBE_WaitForImport DISABLED_WaitForImport | 167 #define MAYBE_ImportBookmarksFile DISABLED_ImportBookmarksFile |
129 #else | 168 #else |
130 #define MAYBE_WaitForImport WaitForImport | 169 #define MAYBE_ImportBookmarksFile ImportBookmarksFile |
131 #endif | 170 #endif |
132 | 171 |
133 IN_PROC_BROWSER_TEST_F(FirstRunIntegrationBrowserTest, MAYBE_WaitForImport) { | 172 // The bookmarks file doesn't actually need to exist for this integration test |
134 bool success = false; | 173 // to trigger the interaction being tested. |
135 EXPECT_TRUE(first_run::DidPerformProfileImport(&success)); | 174 extern const char kImportBookmarksFile[] = |
| 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(); |
136 // Aura builds skip over the import process. | 185 // Aura builds skip over the import process. |
137 #if defined(USE_AURA) | 186 #if defined(USE_AURA) |
138 EXPECT_FALSE(success); | 187 EXPECT_EQ(first_run::AUTO_IMPORT_CALLED, auto_import_state); |
139 #else | 188 #else |
140 EXPECT_TRUE(success); | 189 EXPECT_EQ(first_run::AUTO_IMPORT_CALLED | |
| 190 first_run::AUTO_IMPORT_PROFILE_IMPORTED | |
| 191 first_run::AUTO_IMPORT_BOOKMARKS_FILE_IMPORTED, |
| 192 auto_import_state); |
141 #endif | 193 #endif |
142 } | 194 } |
143 | 195 |
144 // Test an import with all import options disabled. This is a regression test | 196 // 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 | 197 // 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. | 198 // stay running, and the NTP to be loaded with no apps. |
147 IN_PROC_BROWSER_TEST_F(FirstRunMasterPrefsBrowserTest, | 199 extern const char kImportNothing[] = |
| 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, |
148 ImportNothingAndShowNewTabPage) { | 211 ImportNothingAndShowNewTabPage) { |
149 EXPECT_TRUE(first_run::DidPerformProfileImport(NULL)); | 212 EXPECT_EQ(first_run::AUTO_IMPORT_CALLED, first_run::auto_import_state()); |
150 ui_test_utils::NavigateToURLWithDisposition( | 213 ui_test_utils::NavigateToURLWithDisposition( |
151 browser(), GURL(chrome::kChromeUINewTabURL), CURRENT_TAB, | 214 browser(), GURL(chrome::kChromeUINewTabURL), CURRENT_TAB, |
152 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 215 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
153 content::WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(0); | 216 content::WebContents* tab = browser()->tab_strip_model()->GetWebContentsAt(0); |
154 EXPECT_EQ(1, tab->GetMaxPageID()); | 217 EXPECT_EQ(1, tab->GetMaxPageID()); |
155 } | 218 } |
156 | 219 |
157 #endif // !defined(OS_CHROMEOS) | 220 #endif // !defined(OS_CHROMEOS) |
OLD | NEW |