| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> |
| 5 #include <string> | 6 #include <string> |
| 7 #include <vector> |
| 6 | 8 |
| 7 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/browser_commands.h" | |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "content/public/browser/navigation_controller.h" |
| 15 #include "content/public/browser/navigation_entry.h" |
| 13 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/browser/web_ui.h" | 17 #include "content/public/browser/web_ui.h" |
| 15 #include "content/public/browser/web_ui_message_handler.h" | 18 #include "content/public/browser/web_ui_message_handler.h" |
| 16 #include "content/public/common/url_constants.h" | 19 #include "content/public/common/url_constants.h" |
| 17 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
| 18 #include "ui/base/window_open_disposition.h" | 21 #include "ui/base/window_open_disposition.h" |
| 19 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 23 #include "url/url_constants.h" |
| 20 | 24 |
| 21 typedef InProcessBrowserTest MdSettingsUITest; | 25 typedef InProcessBrowserTest MdSettingsUITest; |
| 22 | 26 |
| 23 using ui_test_utils::NavigateToURL; | 27 using ui_test_utils::NavigateToURL; |
| 24 using content::WaitForLoadStop; | |
| 25 | 28 |
| 26 IN_PROC_BROWSER_TEST_F(MdSettingsUITest, ViewSourceDoesntCrash) { | 29 IN_PROC_BROWSER_TEST_F(MdSettingsUITest, ViewSourceDoesntCrash) { |
| 27 NavigateToURL(browser(), | 30 NavigateToURL(browser(), |
| 28 GURL(content::kViewSourceScheme + std::string(":") + | 31 GURL(content::kViewSourceScheme + std::string(":") + |
| 29 chrome::kChromeUIMdSettingsURL)); | 32 chrome::kChromeUIMdSettingsURL)); |
| 30 } | 33 } |
| 31 | 34 |
| 32 // May not complete on memory bots. TODO(dbeam): investigate and fix. | 35 IN_PROC_BROWSER_TEST_F(MdSettingsUITest, BackForwardDoesntCrash) { |
| 33 // See https://crbug.com/558434 and https://crbug.com/620370. | 36 auto contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 34 #if defined(MEMORY_SANITIZER) | |
| 35 #define MAYBE_BackForwardDoesntCrash DISABLED_BackForwardDoesntCrash | |
| 36 #else | |
| 37 #define MAYBE_BackForwardDoesntCrash BackForwardDoesntCrash | |
| 38 #endif | |
| 39 | 37 |
| 40 IN_PROC_BROWSER_TEST_F(MdSettingsUITest, MAYBE_BackForwardDoesntCrash) { | 38 // Build some history. |
| 41 NavigateToURL(browser(), GURL(chrome::kChromeUIMdSettingsURL)); | 39 std::vector<std::unique_ptr<content::NavigationEntry>> entries; |
| 40 entries.push_back(content::NavigationController::CreateNavigationEntry( |
| 41 GURL(url::kAboutBlankURL), |
| 42 content::Referrer(), |
| 43 ui::PAGE_TRANSITION_LINK, |
| 44 true /* is_renderer_initiated */, |
| 45 std::string() /* extra_headers */, |
| 46 contents->GetBrowserContext())); |
| 47 entries.push_back(content::NavigationController::CreateNavigationEntry( |
| 48 GURL(chrome::kChromeUIMdSettingsURL), |
| 49 content::Referrer(), |
| 50 ui::PAGE_TRANSITION_LINK, |
| 51 true /* is_renderer_initiated */, |
| 52 std::string() /* extra_headers */, |
| 53 contents->GetBrowserContext())); |
| 42 | 54 |
| 43 NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); | 55 // Load the built history into the tab via session restore (which should load |
| 56 // about:blank with chrome://md-settings as the URL to visit if forward is |
| 57 // pressed). |
| 58 contents->GetController().Restore( |
| 59 0 /* selected_navigation */, |
| 60 content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, |
| 61 &entries); |
| 62 ASSERT_EQ(0U, entries.size()); |
| 44 | 63 |
| 45 chrome::GoBack(browser(), CURRENT_TAB); | 64 ASSERT_TRUE(contents->GetController().CanGoForward()); |
| 46 WaitForLoadStop(browser()->tab_strip_model()->GetActiveWebContents()); | 65 contents->GetController().GoForward(); |
| 66 |
| 67 // Go forward to visit chrome://md-settings. |
| 68 ASSERT_TRUE(contents->GetController().CanGoForward()); |
| 69 contents->GetController().GoForward(); |
| 70 |
| 71 // TODO(dbeam): do we need to wait until load stop? Is there anything else we |
| 72 // could wait for that reliably constructs handlers but is faster? |
| 73 ASSERT_TRUE(content::WaitForLoadStop(contents)); |
| 74 EXPECT_EQ(GURL(chrome::kChromeUIMdSettingsURL), |
| 75 contents->GetLastCommittedURL()); |
| 47 } | 76 } |
| 48 | 77 |
| 49 // Catch lifetime issues in message handlers. There was previously a problem | 78 // Catch lifetime issues in message handlers. There was previously a problem |
| 50 // with PrefMember calling Init again after Destroy. | 79 // with PrefMember calling Init again after Destroy. |
| 51 IN_PROC_BROWSER_TEST_F(MdSettingsUITest, ToggleJavaScript) { | 80 IN_PROC_BROWSER_TEST_F(MdSettingsUITest, ToggleJavaScript) { |
| 52 NavigateToURL(browser(), GURL(chrome::kChromeUIMdSettingsURL)); | 81 NavigateToURL(browser(), GURL(chrome::kChromeUIMdSettingsURL)); |
| 53 | 82 |
| 54 auto handlers = browser()->tab_strip_model()->GetActiveWebContents() | 83 auto handlers = browser()->tab_strip_model()->GetActiveWebContents() |
| 55 ->GetWebUI()->GetHandlersForTesting(); | 84 ->GetWebUI()->GetHandlersForTesting(); |
| 56 | 85 |
| 57 for (content::WebUIMessageHandler* handler : *handlers) { | 86 for (content::WebUIMessageHandler* handler : *handlers) { |
| 58 handler->AllowJavascriptForTesting(); | 87 handler->AllowJavascriptForTesting(); |
| 59 handler->DisallowJavascript(); | 88 handler->DisallowJavascript(); |
| 60 handler->AllowJavascriptForTesting(); | 89 handler->AllowJavascriptForTesting(); |
| 61 } | 90 } |
| 62 } | 91 } |
| OLD | NEW |