summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-22 20:32:53 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-22 20:32:53 +0000
commitb8f61dc7f14f6682d7895fa40222510907b144fe (patch)
tree94901cdd58cc8f14539181e13d1816320af68be9
parentd667ecb27955399fa1d5002dd0b616771e451171 (diff)
downloadchromium_src-b8f61dc7f14f6682d7895fa40222510907b144fe.zip
chromium_src-b8f61dc7f14f6682d7895fa40222510907b144fe.tar.gz
chromium_src-b8f61dc7f14f6682d7895fa40222510907b144fe.tar.bz2
TTF: Write tests for FirstRun.
BUG=none TEST=FirstRunTest.* Review URL: http://codereview.chromium.org/2862024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50513 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/first_run.cc89
-rw-r--r--chrome/browser/first_run.h7
-rw-r--r--chrome/browser/first_run_browsertest.cc52
-rw-r--r--chrome/browser/first_run_gtk.cc13
-rw-r--r--chrome/browser/first_run_unittest.cc24
-rw-r--r--chrome/browser/first_run_win.cc12
-rwxr-xr-xchrome/chrome_tests.gypi2
7 files changed, 141 insertions, 58 deletions
diff --git a/chrome/browser/first_run.cc b/chrome/browser/first_run.cc
index 4ef364b..252686c 100644
--- a/chrome/browser/first_run.cc
+++ b/chrome/browser/first_run.cc
@@ -25,31 +25,29 @@ namespace {
// The kSentinelFile file absence will tell us it is a first run.
const char kSentinelFile[] = "First Run";
-// Gives the full path to the sentinel file. The file might not exist.
-bool GetFirstRunSentinelFilePath(FilePath* path) {
- FilePath first_run_sentinel;
+} // namespace
-#if defined(OS_WIN)
- FilePath exe_path;
- if (!PathService::Get(base::DIR_EXE, &exe_path))
- return false;
- if (InstallUtil::IsPerUserInstall(exe_path.value().c_str())) {
- first_run_sentinel = exe_path;
- } else {
- if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel))
- return false;
+// TODO(port): Import switches need to be ported to both Mac and Linux. Not all
+// import switches here are implemented for Linux. None are implemented for Mac
+// (as this function will not be called on Mac).
+int FirstRun::ImportNow(Profile* profile, const CommandLine& cmdline) {
+ int return_code = true;
+ if (cmdline.HasSwitch(switches::kImportFromFile)) {
+ // Silently import preset bookmarks from file.
+ // This is an OEM scenario.
+ return_code = ImportFromFile(profile, cmdline);
}
+ if (cmdline.HasSwitch(switches::kImport)) {
+#if defined(OS_WIN)
+ return_code = ImportFromBrowser(profile, cmdline);
#else
- if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel))
- return false;
+ NOTIMPLEMENTED();
#endif
-
- *path = first_run_sentinel.AppendASCII(kSentinelFile);
- return true;
+ }
+ return return_code;
}
-} // namespace
-
+// static
bool FirstRun::IsChromeFirstRun() {
// A troolean, 0 means not yet set, 1 means set to true, 2 set to false.
static int first_run = 0;
@@ -66,6 +64,7 @@ bool FirstRun::IsChromeFirstRun() {
return true;
}
+// static
bool FirstRun::RemoveSentinel() {
FilePath first_run_sentinel;
if (!GetFirstRunSentinelFilePath(&first_run_sentinel))
@@ -73,6 +72,7 @@ bool FirstRun::RemoveSentinel() {
return file_util::Delete(first_run_sentinel, false);
}
+// static
bool FirstRun::CreateSentinel() {
FilePath first_run_sentinel;
if (!GetFirstRunSentinelFilePath(&first_run_sentinel))
@@ -80,6 +80,7 @@ bool FirstRun::CreateSentinel() {
return file_util::WriteFile(first_run_sentinel, "", 0) != -1;
}
+// static
bool FirstRun::SetShowFirstRunBubblePref() {
PrefService* local_state = g_browser_process->local_state();
if (!local_state)
@@ -91,6 +92,7 @@ bool FirstRun::SetShowFirstRunBubblePref() {
return true;
}
+// static
bool FirstRun::SetShowWelcomePagePref() {
PrefService* local_state = g_browser_process->local_state();
if (!local_state)
@@ -102,6 +104,7 @@ bool FirstRun::SetShowWelcomePagePref() {
return true;
}
+// static
bool FirstRun::SetOEMFirstRunBubblePref() {
PrefService* local_state = g_browser_process->local_state();
if (!local_state)
@@ -114,6 +117,7 @@ bool FirstRun::SetOEMFirstRunBubblePref() {
return true;
}
+// static
bool FirstRun::SetMinimalFirstRunBubblePref() {
PrefService* local_state = g_browser_process->local_state();
if (!local_state)
@@ -126,6 +130,7 @@ bool FirstRun::SetMinimalFirstRunBubblePref() {
return true;
}
+// static
int FirstRun::ImportFromFile(Profile* profile, const CommandLine& cmdline) {
FilePath file_path = cmdline.GetSwitchValuePath(switches::kImportFromFile);
if (file_path.empty()) {
@@ -154,25 +159,43 @@ int FirstRun::ImportFromFile(Profile* profile, const CommandLine& cmdline) {
return observer.import_result();
}
-// TODO(port): Import switches need ported to both Mac and Linux. Not all
-// import switches here are implemented for Linux. None are implemented for
-// Mac (as this function will not be called on Mac).
-int FirstRun::ImportNow(Profile* profile, const CommandLine& cmdline) {
- int return_code = true;
- if (cmdline.HasSwitch(switches::kImportFromFile)) {
- // Silently import preset bookmarks from file.
- // This is an OEM scenario.
- return_code = ImportFromFile(profile, cmdline);
- }
- if (cmdline.HasSwitch(switches::kImport)) {
+// static
+bool FirstRun::GetFirstRunSentinelFilePath(FilePath* path) {
+ FilePath first_run_sentinel;
+
#if defined(OS_WIN)
- return_code = ImportFromBrowser(profile, cmdline);
+ FilePath exe_path;
+ if (!PathService::Get(base::DIR_EXE, &exe_path))
+ return false;
+ if (InstallUtil::IsPerUserInstall(exe_path.value().c_str())) {
+ first_run_sentinel = exe_path;
+ } else {
+ if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel))
+ return false;
+ }
#else
- NOTIMPLEMENTED();
+ if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel))
+ return false;
#endif
+
+ *path = first_run_sentinel.AppendASCII(kSentinelFile);
+ return true;
+}
+
+#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
+// static
+void Upgrade::RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
+ if (new_command_line_) {
+ if (!RelaunchChromeBrowser(*new_command_line_)) {
+ DLOG(ERROR) << "Launching a new instance of the browser failed.";
+ } else {
+ DLOG(WARNING) << "Launched a new instance of the browser.";
+ }
+ delete new_command_line_;
+ new_command_line_ = NULL;
}
- return return_code;
}
+#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
int FirstRunImportObserver::import_result() const {
return import_result_;
diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h
index 6994855..df5af39 100644
--- a/chrome/browser/first_run.h
+++ b/chrome/browser/first_run.h
@@ -115,6 +115,8 @@ class FirstRun {
static bool SetShowWelcomePagePref();
private:
+ friend class FirstRunTest;
+
#if defined(OS_WIN)
// Imports settings in a separate process. It is the implementation of the
// public version.
@@ -128,9 +130,14 @@ class FirstRun {
#elif defined(OS_LINUX)
static bool ImportBookmarks(const std::wstring& import_bookmarks_path);
#endif
+
// Import bookmarks from an html file. The path to the file is provided in
// the command line.
static int ImportFromFile(Profile* profile, const CommandLine& cmdline);
+
+ // Gives the full path to the sentinel file. The file might not exist.
+ static bool GetFirstRunSentinelFilePath(FilePath* path);
+
// This class is for scoping purposes.
DISALLOW_IMPLICIT_CONSTRUCTORS(FirstRun);
};
diff --git a/chrome/browser/first_run_browsertest.cc b/chrome/browser/first_run_browsertest.cc
new file mode 100644
index 0000000..3e59aca
--- /dev/null
+++ b/chrome/browser/first_run_browsertest.cc
@@ -0,0 +1,52 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/first_run.h"
+#include "chrome/browser/pref_service.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+typedef InProcessBrowserTest FirstRunBrowserTest;
+
+IN_PROC_BROWSER_TEST_F(FirstRunBrowserTest, SetShowFirstRunBubblePref) {
+ EXPECT_FALSE(g_browser_process->local_state()->FindPreference(
+ prefs::kShouldShowFirstRunBubble));
+ EXPECT_TRUE(FirstRun::SetShowFirstRunBubblePref());
+ ASSERT_TRUE(g_browser_process->local_state()->FindPreference(
+ prefs::kShouldShowFirstRunBubble));
+ EXPECT_TRUE(g_browser_process->local_state()->GetBoolean(
+ prefs::kShouldShowFirstRunBubble));
+}
+
+IN_PROC_BROWSER_TEST_F(FirstRunBrowserTest, SetShowWelcomePagePref) {
+ EXPECT_FALSE(g_browser_process->local_state()->FindPreference(
+ prefs::kShouldShowWelcomePage));
+ EXPECT_TRUE(FirstRun::SetShowWelcomePagePref());
+ ASSERT_TRUE(g_browser_process->local_state()->FindPreference(
+ prefs::kShouldShowWelcomePage));
+ EXPECT_TRUE(g_browser_process->local_state()->GetBoolean(
+ prefs::kShouldShowWelcomePage));
+}
+
+IN_PROC_BROWSER_TEST_F(FirstRunBrowserTest, SetOEMFirstRunBubblePref) {
+ EXPECT_FALSE(g_browser_process->local_state()->FindPreference(
+ prefs::kShouldUseOEMFirstRunBubble));
+ EXPECT_TRUE(FirstRun::SetOEMFirstRunBubblePref());
+ ASSERT_TRUE(g_browser_process->local_state()->FindPreference(
+ prefs::kShouldUseOEMFirstRunBubble));
+ EXPECT_TRUE(g_browser_process->local_state()->GetBoolean(
+ prefs::kShouldUseOEMFirstRunBubble));
+}
+
+IN_PROC_BROWSER_TEST_F(FirstRunBrowserTest, SetMinimalFirstRunBubblePref) {
+ EXPECT_FALSE(g_browser_process->local_state()->FindPreference(
+ prefs::kShouldUseMinimalFirstRunBubble));
+ EXPECT_TRUE(FirstRun::SetMinimalFirstRunBubblePref());
+ ASSERT_TRUE(g_browser_process->local_state()->FindPreference(
+ prefs::kShouldUseMinimalFirstRunBubble));
+ EXPECT_TRUE(g_browser_process->local_state()->GetBoolean(
+ prefs::kShouldUseMinimalFirstRunBubble));
+}
diff --git a/chrome/browser/first_run_gtk.cc b/chrome/browser/first_run_gtk.cc
index c35063d..15ebefe 100644
--- a/chrome/browser/first_run_gtk.cc
+++ b/chrome/browser/first_run_gtk.cc
@@ -160,19 +160,6 @@ bool Upgrade::RelaunchChromeBrowser(const CommandLine& command_line) {
}
// static
-void Upgrade::RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
- if (new_command_line_) {
- if (!base::LaunchApp(*new_command_line_, false, false, NULL)) {
- DLOG(ERROR) << "Launching a new instance of the browser failed.";
- } else {
- DLOG(WARNING) << "Launched a new instance of the browser.";
- }
- delete new_command_line_;
- new_command_line_ = NULL;
- }
-}
-
-// static
double Upgrade::GetLastModifiedTimeOfExe() {
FilePath exe_file_path;
if (!PathService::Get(base::FILE_EXE, &exe_file_path)) {
diff --git a/chrome/browser/first_run_unittest.cc b/chrome/browser/first_run_unittest.cc
new file mode 100644
index 0000000..8555370
--- /dev/null
+++ b/chrome/browser/first_run_unittest.cc
@@ -0,0 +1,24 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/file_util.h"
+#include "chrome/browser/first_run.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class FirstRunTest : public testing::Test {
+ protected:
+ virtual void SetUp() {
+ FirstRun::GetFirstRunSentinelFilePath(&sentinel_path_);
+ }
+
+ FilePath sentinel_path_;
+};
+
+TEST_F(FirstRunTest, RemoveSentinel) {
+ EXPECT_TRUE(FirstRun::CreateSentinel());
+ EXPECT_TRUE(file_util::PathExists(sentinel_path_));
+
+ EXPECT_TRUE(FirstRun::RemoveSentinel());
+ EXPECT_FALSE(file_util::PathExists(sentinel_path_));
+}
diff --git a/chrome/browser/first_run_win.cc b/chrome/browser/first_run_win.cc
index 512385c..14c1682 100644
--- a/chrome/browser/first_run_win.cc
+++ b/chrome/browser/first_run_win.cc
@@ -416,18 +416,6 @@ bool Upgrade::RelaunchChromeBrowser(const CommandLine& command_line) {
false, false, NULL);
}
-void Upgrade::RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
- if (new_command_line_) {
- if (RelaunchChromeBrowser(*new_command_line_)) {
- DLOG(ERROR) << "Launching a new instance of the browser failed.";
- } else {
- DLOG(WARNING) << "Launched a new instance of the browser.";
- }
- delete new_command_line_;
- new_command_line_ = NULL;
- }
-}
-
bool Upgrade::SwapNewChromeExeIfPresent() {
FilePath new_chrome_exe;
if (!GetNewerChromeFile(&new_chrome_exe))
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 0b6099b..7aca192 100755
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -792,6 +792,7 @@
'browser/extensions/user_script_master_unittest.cc',
'browser/file_watcher_unittest.cc',
'browser/find_backend_unittest.cc',
+ 'browser/first_run_unittest.cc',
'browser/geolocation/fake_access_token_store.h',
'browser/geolocation/geolocation_content_settings_map_unittest.cc',
'browser/geolocation/geolocation_exceptions_table_model_unittest.cc',
@@ -1394,6 +1395,7 @@
'browser/extensions/permissions_apitest.cc',
'browser/extensions/stubs_apitest.cc',
'browser/find_bar_host_browsertest.cc',
+ 'browser/first_run_browsertest.cc',
'browser/geolocation/access_token_store_browsertest.cc',
'browser/geolocation/geolocation_browsertest.cc',
'browser/net/cookie_policy_browsertest.cc',