Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / sessions / session_restore_browsertest_chromeos.cc
blob98cccc623dc89f191ccd9a35118a053ff754816f
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
3 // found in the LICENSE file.
5 #include <list>
6 #include <vector>
8 #include "base/command_line.h"
9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/defaults.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_iterator.h"
15 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/host_desktop.h"
17 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "components/sessions/serialized_navigation_entry_test_helper.h"
21 #include "content/public/browser/notification_service.h"
22 #include "content/public/test/test_utils.h"
24 namespace {
25 const char* test_app_popup_name1 = "TestApp1";
26 const char* test_app_popup_name2 = "TestApp2";
29 class SessionRestoreTestChromeOS : public InProcessBrowserTest {
30 public:
31 ~SessionRestoreTestChromeOS() override {}
33 protected:
34 void SetUpCommandLine(base::CommandLine* command_line) override {
35 InProcessBrowserTest::SetUpCommandLine(command_line);
38 Browser* CreateBrowserWithParams(Browser::CreateParams params) {
39 Browser* browser = new Browser(params);
40 AddBlankTabAndShow(browser);
41 browser_list_.push_back(browser);
42 return browser;
45 bool CloseBrowser(Browser* browser) {
46 for (std::list<Browser*>::iterator iter = browser_list_.begin();
47 iter != browser_list_.end(); ++iter) {
48 if (*iter == browser) {
49 CloseBrowserSynchronously(*iter);
50 browser_list_.erase(iter);
51 return true;
54 return false;
57 Browser::CreateParams CreateParamsForApp(const std::string name,
58 bool trusted) {
59 return Browser::CreateParams::CreateForApp(
60 name, trusted, gfx::Rect(), profile(), chrome::GetActiveDesktop());
63 // Turn on session restore before we restart.
64 void TurnOnSessionRestore() {
65 SessionStartupPref::SetStartupPref(
66 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST));
69 Profile* profile() { return browser()->profile(); }
71 std::list<Browser*> browser_list_;
74 // Thse tests are in pairs. The PRE_ test creates some browser windows and
75 // the following test confirms that the correct windows are restored after a
76 // restart.
78 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreBrowserWindows) {
79 // One browser window is always created by default.
80 EXPECT_TRUE(browser());
81 // Create a second normal browser window.
82 CreateBrowserWithParams(
83 Browser::CreateParams(profile(), chrome::GetActiveDesktop()));
84 // Create a third incognito browser window which should not get restored.
85 CreateBrowserWithParams(Browser::CreateParams(
86 profile()->GetOffTheRecordProfile(), chrome::GetActiveDesktop()));
87 TurnOnSessionRestore();
90 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreBrowserWindows) {
91 size_t total_count = 0;
92 size_t incognito_count = 0;
93 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
94 ++total_count;
95 if (it->profile()->IsOffTheRecord())
96 ++incognito_count;
98 EXPECT_EQ(2u, total_count);
99 EXPECT_EQ(0u, incognito_count);
102 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreAppsV1) {
103 // Create a trusted app popup.
104 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name1, true));
105 // Create a second trusted app with two popup windows.
106 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name2, true));
107 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name2, true));
108 // Create a third untrusted (child) app3 popup. This should not get restored.
109 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name2, false));
111 TurnOnSessionRestore();
114 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreAppsV1) {
115 size_t total_count = 0;
116 size_t app1_count = 0;
117 size_t app2_count = 0;
118 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
119 ++total_count;
120 if (it->app_name() == test_app_popup_name1)
121 ++app1_count;
122 if (it->app_name() == test_app_popup_name2)
123 ++app2_count;
125 EXPECT_EQ(1u, app1_count);
126 EXPECT_EQ(2u, app2_count); // Only the trusted app windows are restored.
127 EXPECT_EQ(4u, total_count); // Default browser() + 3 app windows
130 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreMaximized) {
131 // One browser window is always created by default.
132 ASSERT_TRUE(browser());
133 // Create a second browser window and maximize it.
134 Browser* browser2 = CreateBrowserWithParams(
135 Browser::CreateParams(profile(), chrome::GetActiveDesktop()));
136 browser2->window()->Maximize();
138 // Create two app popup windows and maximize the second one.
139 Browser* app_browser1 =
140 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name1, true));
141 Browser* app_browser2 =
142 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name1, true));
143 app_browser2->window()->Maximize();
145 EXPECT_FALSE(browser()->window()->IsMaximized());
146 EXPECT_TRUE(browser2->window()->IsMaximized());
147 EXPECT_FALSE(app_browser1->window()->IsMaximized());
148 EXPECT_TRUE(app_browser2->window()->IsMaximized());
150 TurnOnSessionRestore();
153 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreMaximized) {
154 size_t total_count = 0;
155 size_t maximized_count = 0;
156 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
157 ++total_count;
158 if (it->window()->IsMaximized())
159 ++maximized_count;
161 EXPECT_EQ(4u, total_count);
162 EXPECT_EQ(2u, maximized_count);