| OLD | NEW | 
|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <string> | 5 #include <string> | 
| 6 | 6 | 
| 7 #include "base/bind.h" | 7 #include "base/bind.h" | 
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" | 
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" | 
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" | 
|  | 11 #include "base/location.h" | 
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" | 
| 12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" | 
|  | 14 #include "base/single_thread_task_runner.h" | 
| 13 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" | 
| 14 #include "base/sys_info.h" | 16 #include "base/sys_info.h" | 
|  | 17 #include "base/thread_task_runner_handle.h" | 
| 15 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" | 
| 16 #include "chrome/browser/chrome_content_browser_client.h" | 19 #include "chrome/browser/chrome_content_browser_client.h" | 
| 17 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" | 
| 18 #include "chrome/browser/command_updater.h" | 21 #include "chrome/browser/command_updater.h" | 
| 19 #include "chrome/browser/defaults.h" | 22 #include "chrome/browser/defaults.h" | 
| 20 #include "chrome/browser/devtools/devtools_window_testing.h" | 23 #include "chrome/browser/devtools/devtools_window_testing.h" | 
| 21 #include "chrome/browser/extensions/extension_browsertest.h" | 24 #include "chrome/browser/extensions/extension_browsertest.h" | 
| 22 #include "chrome/browser/extensions/extension_service.h" | 25 #include "chrome/browser/extensions/extension_service.h" | 
| 23 #include "chrome/browser/extensions/extension_util.h" | 26 #include "chrome/browser/extensions/extension_util.h" | 
| 24 #include "chrome/browser/extensions/tab_helper.h" | 27 #include "chrome/browser/extensions/tab_helper.h" | 
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 197 | 200 | 
| 198 // Used by CloseWithAppMenuOpen. Invokes CloseWindow on the supplied browser. | 201 // Used by CloseWithAppMenuOpen. Invokes CloseWindow on the supplied browser. | 
| 199 void CloseWindowCallback(Browser* browser) { | 202 void CloseWindowCallback(Browser* browser) { | 
| 200   chrome::CloseWindow(browser); | 203   chrome::CloseWindow(browser); | 
| 201 } | 204 } | 
| 202 | 205 | 
| 203 // Used by CloseWithAppMenuOpen. Posts a CloseWindowCallback and shows the app | 206 // Used by CloseWithAppMenuOpen. Posts a CloseWindowCallback and shows the app | 
| 204 // menu. | 207 // menu. | 
| 205 void RunCloseWithAppMenuCallback(Browser* browser) { | 208 void RunCloseWithAppMenuCallback(Browser* browser) { | 
| 206   // ShowAppMenu is modal under views. Schedule a task that closes the window. | 209   // ShowAppMenu is modal under views. Schedule a task that closes the window. | 
| 207   base::MessageLoop::current()->PostTask( | 210   base::ThreadTaskRunnerHandle::Get()->PostTask( | 
| 208       FROM_HERE, base::Bind(&CloseWindowCallback, browser)); | 211       FROM_HERE, base::Bind(&CloseWindowCallback, browser)); | 
| 209   chrome::ShowAppMenu(browser); | 212   chrome::ShowAppMenu(browser); | 
| 210 } | 213 } | 
| 211 | 214 | 
| 212 // Displays "INTERSTITIAL" while the interstitial is attached. | 215 // Displays "INTERSTITIAL" while the interstitial is attached. | 
| 213 // (InterstitialPage can be used in a test directly, but there would be no way | 216 // (InterstitialPage can be used in a test directly, but there would be no way | 
| 214 // to visually tell if it is showing or not.) | 217 // to visually tell if it is showing or not.) | 
| 215 class TestInterstitialPage : public content::InterstitialPageDelegate { | 218 class TestInterstitialPage : public content::InterstitialPageDelegate { | 
| 216  public: | 219  public: | 
| 217   TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) { | 220   TestInterstitialPage(WebContents* tab, bool new_navigation, const GURL& url) { | 
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 866   // ensures that it happens through the single IDC_EXIT of the test. | 869   // ensures that it happens through the single IDC_EXIT of the test. | 
| 867   void TearDownOnMainThread() override { | 870   void TearDownOnMainThread() override { | 
| 868     // Cycle both the MessageLoop and the Cocoa runloop twice to flush out any | 871     // Cycle both the MessageLoop and the Cocoa runloop twice to flush out any | 
| 869     // Chrome work that generates Cocoa work. Do this twice since there are two | 872     // Chrome work that generates Cocoa work. Do this twice since there are two | 
| 870     // Browsers that must be closed. | 873     // Browsers that must be closed. | 
| 871     CycleRunLoops(); | 874     CycleRunLoops(); | 
| 872     CycleRunLoops(); | 875     CycleRunLoops(); | 
| 873 | 876 | 
| 874     // Run the application event loop to completion, which will cycle the | 877     // Run the application event loop to completion, which will cycle the | 
| 875     // native MessagePump on all platforms. | 878     // native MessagePump on all platforms. | 
| 876     base::MessageLoop::current()->PostTask(FROM_HERE, | 879     base::ThreadTaskRunnerHandle::Get()->PostTask( | 
| 877                                            base::MessageLoop::QuitClosure()); | 880         FROM_HERE, base::MessageLoop::QuitClosure()); | 
| 878     base::MessageLoop::current()->Run(); | 881     base::MessageLoop::current()->Run(); | 
| 879 | 882 | 
| 880     // Take care of any remaining Cocoa work. | 883     // Take care of any remaining Cocoa work. | 
| 881     CycleRunLoops(); | 884     CycleRunLoops(); | 
| 882 | 885 | 
| 883     // At this point, quit should be for real now. | 886     // At this point, quit should be for real now. | 
| 884     ASSERT_EQ(0u, chrome::GetTotalBrowserCount()); | 887     ASSERT_EQ(0u, chrome::GetTotalBrowserCount()); | 
| 885   } | 888   } | 
| 886 | 889 | 
| 887   // A helper function that cycles the MessageLoop, and on Mac, the Cocoa run | 890   // A helper function that cycles the MessageLoop, and on Mac, the Cocoa run | 
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1539 } | 1542 } | 
| 1540 #endif  // !defined(OS_CHROMEOS) | 1543 #endif  // !defined(OS_CHROMEOS) | 
| 1541 | 1544 | 
| 1542 // This test verifies we don't crash when closing the last window and the app | 1545 // This test verifies we don't crash when closing the last window and the app | 
| 1543 // menu is showing. | 1546 // menu is showing. | 
| 1544 IN_PROC_BROWSER_TEST_F(BrowserTest, CloseWithAppMenuOpen) { | 1547 IN_PROC_BROWSER_TEST_F(BrowserTest, CloseWithAppMenuOpen) { | 
| 1545   if (browser_defaults::kBrowserAliveWithNoWindows) | 1548   if (browser_defaults::kBrowserAliveWithNoWindows) | 
| 1546     return; | 1549     return; | 
| 1547 | 1550 | 
| 1548   // We need a message loop running for menus on windows. | 1551   // We need a message loop running for menus on windows. | 
| 1549   base::MessageLoop::current()->PostTask( | 1552   base::ThreadTaskRunnerHandle::Get()->PostTask( | 
| 1550       FROM_HERE, base::Bind(&RunCloseWithAppMenuCallback, browser())); | 1553       FROM_HERE, base::Bind(&RunCloseWithAppMenuCallback, browser())); | 
| 1551 } | 1554 } | 
| 1552 | 1555 | 
| 1553 #if !defined(OS_MACOSX) | 1556 #if !defined(OS_MACOSX) | 
| 1554 IN_PROC_BROWSER_TEST_F(BrowserTest, OpenAppWindowLikeNtp) { | 1557 IN_PROC_BROWSER_TEST_F(BrowserTest, OpenAppWindowLikeNtp) { | 
| 1555   ASSERT_TRUE(test_server()->Start()); | 1558   ASSERT_TRUE(test_server()->Start()); | 
| 1556 | 1559 | 
| 1557   // Load an app | 1560   // Load an app | 
| 1558   host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 1561   host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 
| 1559   ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); | 1562   ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); | 
| (...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2761   // Don't proceed and wait for interstitial to detach. This doesn't | 2764   // Don't proceed and wait for interstitial to detach. This doesn't | 
| 2762   // destroy |contents|. | 2765   // destroy |contents|. | 
| 2763   interstitial->DontProceed(); | 2766   interstitial->DontProceed(); | 
| 2764   content::WaitForInterstitialDetach(web_contents); | 2767   content::WaitForInterstitialDetach(web_contents); | 
| 2765   // interstitial is deleted now. | 2768   // interstitial is deleted now. | 
| 2766 | 2769 | 
| 2767   EXPECT_TRUE(chrome::CanDuplicateTab(browser())); | 2770   EXPECT_TRUE(chrome::CanDuplicateTab(browser())); | 
| 2768   EXPECT_TRUE(chrome::CanDuplicateTabAt(browser(), 0)); | 2771   EXPECT_TRUE(chrome::CanDuplicateTabAt(browser(), 0)); | 
| 2769   EXPECT_TRUE(chrome::CanDuplicateTabAt(browser(), 1)); | 2772   EXPECT_TRUE(chrome::CanDuplicateTabAt(browser(), 1)); | 
| 2770 } | 2773 } | 
| OLD | NEW | 
|---|