1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chrome_browser_main_win.h"
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/common/pref_names.h"
9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "components/prefs/pref_service.h"
11 #include "components/version_info/version_info.h"
12 #include "content/public/test/browser_test.h"
13 #include "content/public/test/test_utils.h"
15 class ChromeBrowserMainWinTest : public InProcessBrowserTest {
17 // InProcessBrowserTest
18 void SetUpLocalStatePrefService(PrefService* local_state) override {
19 InProcessBrowserTest::SetUpLocalStatePrefService(local_state);
20 if (GetTestPreCount() > 0) {
21 // Clear the migration version pref set by
22 // InProcessBrowserTest::SetUpLocalStatePrefService.
23 local_state->ClearPref(prefs::kShortcutMigrationVersion);
25 // Set the version back to kLastVersionNeedingMigration and
26 // `ShortcutsAreMigratedOnce` will verify that it's not migrated again.
27 local_state->SetString(prefs::kShortcutMigrationVersion, "86.0.4231.0");
32 IN_PROC_BROWSER_TEST_F(ChromeBrowserMainWinTest, PRE_ShortcutsAreMigratedOnce) {
33 // Wait for all startup tasks to run.
34 content::RunAllTasksUntilIdle();
36 // Confirm that shortcuts were migrated.
37 const std::string last_version_migrated =
38 g_browser_process->local_state()->GetString(
39 prefs::kShortcutMigrationVersion);
40 EXPECT_EQ(last_version_migrated, version_info::GetVersionNumber());
43 IN_PROC_BROWSER_TEST_F(ChromeBrowserMainWinTest, ShortcutsAreMigratedOnce) {
44 content::RunAllTasksUntilIdle();
46 // Confirm that shortcuts weren't migrated when marked as having last been
47 // migrated in kLastVersionNeedingMigration+.
48 const std::string last_version_migrated =
49 g_browser_process->local_state()->GetString(
50 prefs::kShortcutMigrationVersion);
51 EXPECT_EQ(last_version_migrated, "86.0.4231.0");