| 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 <list> | 5 #include <list> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" |
| 8 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/defaults.h" | 12 #include "chrome/browser/defaults.h" |
| 12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_iterator.h" | 14 #include "chrome/browser/ui/browser_iterator.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/browser/ui/host_desktop.h" | 16 #include "chrome/browser/ui/host_desktop.h" |
| 16 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 18 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "components/sessions/serialized_navigation_entry_test_helper.h" | 21 #include "components/sessions/serialized_navigation_entry_test_helper.h" |
| 20 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 const char* test_app_popup_name1 = "TestApp1"; | 26 const char* test_app_popup_name1 = "TestApp1"; |
| 25 const char* test_app_popup_name2 = "TestApp2"; | 27 const char* test_app_popup_name2 = "TestApp2"; |
| 26 } | 28 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 browser->window()->Close(); | 62 browser->window()->Close(); |
| 61 observer.Wait(); | 63 observer.Wait(); |
| 62 } | 64 } |
| 63 | 65 |
| 64 Browser::CreateParams CreateParamsForApp(const std::string name, | 66 Browser::CreateParams CreateParamsForApp(const std::string name, |
| 65 bool trusted) { | 67 bool trusted) { |
| 66 return Browser::CreateParams::CreateForApp( | 68 return Browser::CreateParams::CreateForApp( |
| 67 name, trusted, gfx::Rect(), profile(), chrome::GetActiveDesktop()); | 69 name, trusted, gfx::Rect(), profile(), chrome::GetActiveDesktop()); |
| 68 } | 70 } |
| 69 | 71 |
| 70 // Simluate restarting the browser | 72 // Turn on session restore before we restart. |
| 71 void SetRestart() { | 73 void TurnOnSessionRestore() { |
| 72 PrefService* pref_service = g_browser_process->local_state(); | 74 SessionStartupPref::SetStartupPref( |
| 73 pref_service->SetBoolean(prefs::kWasRestarted, true); | 75 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); |
| 74 } | 76 } |
| 75 | 77 |
| 76 Profile* profile() { return browser()->profile(); } | 78 Profile* profile() { return browser()->profile(); } |
| 77 | 79 |
| 78 std::list<Browser*> browser_list_; | 80 std::list<Browser*> browser_list_; |
| 79 }; | 81 }; |
| 80 | 82 |
| 81 // Thse tests are in pairs. The PRE_ test creates some browser windows and | 83 // Thse tests are in pairs. The PRE_ test creates some browser windows and |
| 82 // the following test confirms that the correct windows are restored after a | 84 // the following test confirms that the correct windows are restored after a |
| 83 // restart. | 85 // restart. |
| 84 | 86 |
| 85 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreBrowserWindows) { | 87 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreBrowserWindows) { |
| 86 // One browser window is always created by default. | 88 // One browser window is always created by default. |
| 87 EXPECT_TRUE(browser()); | 89 EXPECT_TRUE(browser()); |
| 88 // Create a second normal browser window. | 90 // Create a second normal browser window. |
| 89 CreateBrowserWithParams( | 91 CreateBrowserWithParams( |
| 90 Browser::CreateParams(profile(), chrome::GetActiveDesktop())); | 92 Browser::CreateParams(profile(), chrome::GetActiveDesktop())); |
| 91 // Create a third incognito browser window which should not get restored. | 93 // Create a third incognito browser window which should not get restored. |
| 92 CreateBrowserWithParams(Browser::CreateParams( | 94 CreateBrowserWithParams(Browser::CreateParams( |
| 93 profile()->GetOffTheRecordProfile(), chrome::GetActiveDesktop())); | 95 profile()->GetOffTheRecordProfile(), chrome::GetActiveDesktop())); |
| 94 SetRestart(); | 96 TurnOnSessionRestore(); |
| 95 } | 97 } |
| 96 | 98 |
| 97 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreBrowserWindows) { | 99 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreBrowserWindows) { |
| 98 size_t total_count = 0; | 100 size_t total_count = 0; |
| 99 size_t incognito_count = 0; | 101 size_t incognito_count = 0; |
| 100 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 102 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 101 ++total_count; | 103 ++total_count; |
| 102 if (it->profile()->IsOffTheRecord()) | 104 if (it->profile()->IsOffTheRecord()) |
| 103 ++incognito_count; | 105 ++incognito_count; |
| 104 } | 106 } |
| 105 EXPECT_EQ(2u, total_count); | 107 EXPECT_EQ(2u, total_count); |
| 106 EXPECT_EQ(0u, incognito_count); | 108 EXPECT_EQ(0u, incognito_count); |
| 107 } | 109 } |
| 108 | 110 |
| 109 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreAppsV1) { | 111 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, PRE_RestoreAppsV1) { |
| 110 // Create a trusted app popup. | 112 // Create a trusted app popup. |
| 111 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name1, true)); | 113 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name1, true)); |
| 112 // Create a second trusted app with two popup windows. | 114 // Create a second trusted app with two popup windows. |
| 113 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name2, true)); | 115 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name2, true)); |
| 114 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name2, true)); | 116 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name2, true)); |
| 115 // Create a third untrusted (child) app3 popup. This should not get restored. | 117 // Create a third untrusted (child) app3 popup. This should not get restored. |
| 116 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name2, false)); | 118 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name2, false)); |
| 117 | 119 |
| 118 SetRestart(); | 120 TurnOnSessionRestore(); |
| 119 } | 121 } |
| 120 | 122 |
| 121 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreAppsV1) { | 123 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreAppsV1) { |
| 122 size_t total_count = 0; | 124 size_t total_count = 0; |
| 123 size_t app1_count = 0; | 125 size_t app1_count = 0; |
| 124 size_t app2_count = 0; | 126 size_t app2_count = 0; |
| 125 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 127 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 126 ++total_count; | 128 ++total_count; |
| 127 if (it->app_name() == test_app_popup_name1) | 129 if (it->app_name() == test_app_popup_name1) |
| 128 ++app1_count; | 130 ++app1_count; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 147 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name1, true)); | 149 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name1, true)); |
| 148 Browser* app_browser2 = | 150 Browser* app_browser2 = |
| 149 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name1, true)); | 151 CreateBrowserWithParams(CreateParamsForApp(test_app_popup_name1, true)); |
| 150 app_browser2->window()->Maximize(); | 152 app_browser2->window()->Maximize(); |
| 151 | 153 |
| 152 EXPECT_FALSE(browser()->window()->IsMaximized()); | 154 EXPECT_FALSE(browser()->window()->IsMaximized()); |
| 153 EXPECT_TRUE(browser2->window()->IsMaximized()); | 155 EXPECT_TRUE(browser2->window()->IsMaximized()); |
| 154 EXPECT_FALSE(app_browser1->window()->IsMaximized()); | 156 EXPECT_FALSE(app_browser1->window()->IsMaximized()); |
| 155 EXPECT_TRUE(app_browser2->window()->IsMaximized()); | 157 EXPECT_TRUE(app_browser2->window()->IsMaximized()); |
| 156 | 158 |
| 157 SetRestart(); | 159 TurnOnSessionRestore(); |
| 158 } | 160 } |
| 159 | 161 |
| 160 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreMaximized) { | 162 IN_PROC_BROWSER_TEST_F(SessionRestoreTestChromeOS, RestoreMaximized) { |
| 161 size_t total_count = 0; | 163 size_t total_count = 0; |
| 162 size_t maximized_count = 0; | 164 size_t maximized_count = 0; |
| 163 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 165 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 164 ++total_count; | 166 ++total_count; |
| 165 if (it->window()->IsMaximized()) | 167 if (it->window()->IsMaximized()) |
| 166 ++maximized_count; | 168 ++maximized_count; |
| 167 } | 169 } |
| 168 EXPECT_EQ(4u, total_count); | 170 EXPECT_EQ(4u, total_count); |
| 169 EXPECT_EQ(2u, maximized_count); | 171 EXPECT_EQ(2u, maximized_count); |
| 170 } | 172 } |
| OLD | NEW |