Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/path_service.h" | 5 #include "base/path_service.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | |
| 8 #include "chrome/browser/apps/app_browsertest_util.h" | 9 #include "chrome/browser/apps/app_browsertest_util.h" |
| 9 #include "chrome/browser/chrome_content_browser_client.h" | 10 #include "chrome/browser/chrome_content_browser_client.h" |
| 10 #include "chrome/browser/prerender/prerender_link_manager.h" | 11 #include "chrome/browser/prerender/prerender_link_manager.h" |
| 11 #include "chrome/browser/prerender/prerender_link_manager_factory.h" | 12 #include "chrome/browser/prerender/prerender_link_manager_factory.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 14 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
| 14 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" | 15 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" |
| 15 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 16 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
| 16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_dialogs.h" | 18 #include "chrome/browser/ui/browser_dialogs.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 // This class intercepts media access request from the embedder. The request | 173 // This class intercepts media access request from the embedder. The request |
| 173 // should be triggered only if the embedder API (from tests) allows the request | 174 // should be triggered only if the embedder API (from tests) allows the request |
| 174 // in Javascript. | 175 // in Javascript. |
| 175 // We do not issue the actual media request; the fact that the request reached | 176 // We do not issue the actual media request; the fact that the request reached |
| 176 // embedder's WebContents is good enough for our tests. This is also to make | 177 // embedder's WebContents is good enough for our tests. This is also to make |
| 177 // the test run successfully on trybots. | 178 // the test run successfully on trybots. |
| 178 class MockWebContentsDelegate : public content::WebContentsDelegate { | 179 class MockWebContentsDelegate : public content::WebContentsDelegate { |
| 179 public: | 180 public: |
| 180 MockWebContentsDelegate() | 181 MockWebContentsDelegate() |
| 181 : requested_(false), | 182 : requested_(false), |
| 182 checked_(false) {} | 183 checked_(false), |
| 184 open_url_from_tab_(false) {} | |
| 183 ~MockWebContentsDelegate() override {} | 185 ~MockWebContentsDelegate() override {} |
| 184 | 186 |
| 185 void RequestMediaAccessPermission( | 187 void RequestMediaAccessPermission( |
| 186 content::WebContents* web_contents, | 188 content::WebContents* web_contents, |
| 187 const content::MediaStreamRequest& request, | 189 const content::MediaStreamRequest& request, |
| 188 const content::MediaResponseCallback& callback) override { | 190 const content::MediaResponseCallback& callback) override { |
| 189 requested_ = true; | 191 requested_ = true; |
| 190 if (request_message_loop_runner_.get()) | 192 if (request_message_loop_runner_.get()) |
| 191 request_message_loop_runner_->Quit(); | 193 request_message_loop_runner_->Quit(); |
| 192 } | 194 } |
| 193 | 195 |
| 194 bool CheckMediaAccessPermission(content::WebContents* web_contents, | 196 bool CheckMediaAccessPermission(content::WebContents* web_contents, |
| 195 const GURL& security_origin, | 197 const GURL& security_origin, |
| 196 content::MediaStreamType type) override { | 198 content::MediaStreamType type) override { |
| 197 checked_ = true; | 199 checked_ = true; |
| 198 if (check_message_loop_runner_.get()) | 200 if (check_message_loop_runner_.get()) |
| 199 check_message_loop_runner_->Quit(); | 201 check_message_loop_runner_->Quit(); |
| 200 return true; | 202 return true; |
| 201 } | 203 } |
| 202 | 204 |
| 205 content::WebContents* OpenURLFromTab( | |
| 206 content::WebContents* source, | |
| 207 const content::OpenURLParams& params) override { | |
| 208 open_url_from_tab_ = true; | |
| 209 if (open_url_message_loop_runner_.get()) | |
| 210 open_url_message_loop_runner_->Quit(); | |
| 211 return NULL; | |
| 212 } | |
| 213 | |
| 203 void WaitForRequestMediaPermission() { | 214 void WaitForRequestMediaPermission() { |
| 204 if (requested_) | 215 if (requested_) |
| 205 return; | 216 return; |
| 206 request_message_loop_runner_ = new content::MessageLoopRunner; | 217 request_message_loop_runner_ = new content::MessageLoopRunner; |
| 207 request_message_loop_runner_->Run(); | 218 request_message_loop_runner_->Run(); |
| 208 } | 219 } |
| 209 | 220 |
| 210 void WaitForCheckMediaPermission() { | 221 void WaitForCheckMediaPermission() { |
| 211 if (checked_) | 222 if (checked_) |
| 212 return; | 223 return; |
| 213 check_message_loop_runner_ = new content::MessageLoopRunner; | 224 check_message_loop_runner_ = new content::MessageLoopRunner; |
| 214 check_message_loop_runner_->Run(); | 225 check_message_loop_runner_->Run(); |
| 215 } | 226 } |
| 216 | 227 |
| 228 void WaitForOpenURLFromTab() { | |
| 229 if (open_url_from_tab_) | |
| 230 return; | |
| 231 open_url_message_loop_runner_ = new content::MessageLoopRunner; | |
| 232 open_url_message_loop_runner_->Run(); | |
| 233 } | |
| 234 | |
| 217 private: | 235 private: |
| 218 bool requested_; | 236 bool requested_; |
| 219 bool checked_; | 237 bool checked_; |
| 238 bool open_url_from_tab_; | |
|
Charlie Reis
2015/02/19 22:56:28
nit: Make past tense, e.g., did_open_url_from_tab_
Fady Samuel
2015/02/20 00:33:06
Done.
| |
| 220 scoped_refptr<content::MessageLoopRunner> request_message_loop_runner_; | 239 scoped_refptr<content::MessageLoopRunner> request_message_loop_runner_; |
| 221 scoped_refptr<content::MessageLoopRunner> check_message_loop_runner_; | 240 scoped_refptr<content::MessageLoopRunner> check_message_loop_runner_; |
| 241 scoped_refptr<content::MessageLoopRunner> open_url_message_loop_runner_; | |
| 222 | 242 |
| 223 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate); | 243 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate); |
| 224 }; | 244 }; |
| 225 | 245 |
| 226 // This class intercepts download request from the guest. | 246 // This class intercepts download request from the guest. |
| 227 class MockDownloadWebContentsDelegate : public content::WebContentsDelegate { | 247 class MockDownloadWebContentsDelegate : public content::WebContentsDelegate { |
| 228 public: | 248 public: |
| 229 explicit MockDownloadWebContentsDelegate( | 249 explicit MockDownloadWebContentsDelegate( |
| 230 content::WebContentsDelegate* orig_delegate) | 250 content::WebContentsDelegate* orig_delegate) |
| 231 : orig_delegate_(orig_delegate), | 251 : orig_delegate_(orig_delegate), |
| (...skipping 1592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1824 EXPECT_TRUE( | 1844 EXPECT_TRUE( |
| 1825 content::ExecuteScript( | 1845 content::ExecuteScript( |
| 1826 embedder_web_contents, | 1846 embedder_web_contents, |
| 1827 base::StringPrintf("startAllowTest('%s')", | 1847 base::StringPrintf("startAllowTest('%s')", |
| 1828 test_name.c_str()))); | 1848 test_name.c_str()))); |
| 1829 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); | 1849 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); |
| 1830 | 1850 |
| 1831 mock->WaitForRequestMediaPermission(); | 1851 mock->WaitForRequestMediaPermission(); |
| 1832 } | 1852 } |
| 1833 | 1853 |
| 1854 IN_PROC_BROWSER_TEST_F(WebViewTest, OpenURLFromTab_CurrentTab_Abort) { | |
| 1855 LoadAppWithGuest("web_view/simple"); | |
| 1856 | |
| 1857 // Verify that OpenURLFromTab with a window disposition of CURRENT_TAB will | |
| 1858 // navigate the current <webview>. | |
| 1859 ExtensionTestMessageListener load_listener("WebViewTest.LOADSTOP", false); | |
| 1860 | |
| 1861 // Navigating to a file URL is forbidden inside a <webview>. | |
| 1862 content::OpenURLParams params(GURL("file://foo"), | |
| 1863 content::Referrer(), | |
| 1864 CURRENT_TAB, | |
| 1865 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
| 1866 true /* is_renderer_initiated */); | |
| 1867 GetGuestWebContents()->GetDelegate()->OpenURLFromTab( | |
| 1868 GetGuestWebContents(), params); | |
| 1869 | |
| 1870 ASSERT_TRUE(load_listener.WaitUntilSatisfied()); | |
| 1871 | |
| 1872 // Verify that the <webview> ends up at about:blank. | |
| 1873 EXPECT_EQ(GURL(url::kAboutBlankURL), | |
| 1874 GetGuestWebContents()->GetLastCommittedURL()); | |
| 1875 } | |
| 1876 | |
| 1877 IN_PROC_BROWSER_TEST_F(WebViewTest, OpenURLFromTab_NewWindow_Abort) { | |
| 1878 LoadAppWithGuest("web_view/simple"); | |
| 1879 | |
| 1880 // Verify that OpenURLFromTab with a window disposition of NEW_BACKGROUND_TAB | |
| 1881 // will trigger the <webview>'s New Window API. | |
| 1882 ExtensionTestMessageListener new_window_listener( | |
| 1883 "WebViewTest.NEWWINDOW", false); | |
| 1884 | |
| 1885 // Navigating to a file URL is forbidden inside a <webview>. | |
| 1886 content::OpenURLParams params(GURL("file://foo"), | |
| 1887 content::Referrer(), | |
| 1888 NEW_BACKGROUND_TAB, | |
| 1889 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
| 1890 true /* is_renderer_initiated */); | |
| 1891 GetGuestWebContents()->GetDelegate()->OpenURLFromTab( | |
| 1892 GetGuestWebContents(), params); | |
| 1893 | |
| 1894 ASSERT_TRUE(new_window_listener.WaitUntilSatisfied()); | |
| 1895 | |
| 1896 content::WebContents* new_guest_web_contents= | |
|
Charlie Reis
2015/02/19 22:56:28
nit: Comma before =
Fady Samuel
2015/02/20 00:33:06
Done.
Charlie Reis
2015/02/20 00:37:59
Ha! Yes, I meant space, of course.
| |
| 1897 GetGuestViewManager()->GetLastGuestCreated(); | |
| 1898 // Verify that a new guest was created. | |
|
Charlie Reis
2015/02/19 22:56:28
nit: Move comment above previous statement.
Fady Samuel
2015/02/20 00:33:06
Done.
| |
| 1899 EXPECT_NE(GetGuestWebContents(), new_guest_web_contents); | |
| 1900 | |
| 1901 // Verify that the new <webview> guest ends up at about:blank. | |
| 1902 EXPECT_EQ(GURL(url::kAboutBlankURL), | |
| 1903 new_guest_web_contents->GetLastCommittedURL()); | |
| 1904 } | |
| 1905 | |
| 1906 IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenuLanguageSettings) { | |
|
Charlie Reis
2015/02/19 22:56:28
nit: Let's add a comment about the test, saying th
Fady Samuel
2015/02/20 00:33:06
Done.
| |
| 1907 LoadAppWithGuest("web_view/context_menus/basic"); | |
| 1908 | |
| 1909 content::WebContents* guest_web_contents = GetGuestWebContents(); | |
| 1910 content::WebContents* embedder = GetEmbedderWebContents(); | |
| 1911 ASSERT_TRUE(embedder); | |
| 1912 scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate()); | |
| 1913 embedder->SetDelegate(mock.get()); | |
| 1914 | |
| 1915 // Create and build our test context menu. | |
| 1916 GURL page_url("http://www.google.com"); | |
| 1917 scoped_ptr<TestRenderViewContextMenu> menu(TestRenderViewContextMenu::Create( | |
| 1918 guest_web_contents, page_url, GURL(), GURL())); | |
| 1919 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS, 0); | |
| 1920 | |
| 1921 mock->WaitForOpenURLFromTab(); | |
|
Charlie Reis
2015/02/19 22:56:28
Can we verify something that shows the navigation
Fady Samuel
2015/02/20 00:33:06
Done.
| |
| 1922 } | |
| 1923 | |
| 1834 IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenusAPI_Basic) { | 1924 IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenusAPI_Basic) { |
| 1835 LoadAppWithGuest("web_view/context_menus/basic"); | 1925 LoadAppWithGuest("web_view/context_menus/basic"); |
| 1836 | 1926 |
| 1837 content::WebContents* guest_web_contents = GetGuestWebContents(); | 1927 content::WebContents* guest_web_contents = GetGuestWebContents(); |
| 1838 content::WebContents* embedder = GetEmbedderWebContents(); | 1928 content::WebContents* embedder = GetEmbedderWebContents(); |
| 1839 ASSERT_TRUE(embedder); | 1929 ASSERT_TRUE(embedder); |
| 1840 | 1930 |
| 1841 // 1. Basic property test. | 1931 // 1. Basic property test. |
| 1842 ExecuteScriptWaitForTitle(embedder, "checkProperties()", "ITEM_CHECKED"); | 1932 ExecuteScriptWaitForTitle(embedder, "checkProperties()", "ITEM_CHECKED"); |
| 1843 | 1933 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1949 #endif | 2039 #endif |
| 1950 | 2040 |
| 1951 // Flaky on Windows. http://crbug.com/303966 | 2041 // Flaky on Windows. http://crbug.com/303966 |
| 1952 #if defined(OS_WIN) | 2042 #if defined(OS_WIN) |
| 1953 #define MAYBE_TearDownTest DISABLED_TearDownTest | 2043 #define MAYBE_TearDownTest DISABLED_TearDownTest |
| 1954 #else | 2044 #else |
| 1955 #define MAYBE_TearDownTest TearDownTest | 2045 #define MAYBE_TearDownTest TearDownTest |
| 1956 #endif | 2046 #endif |
| 1957 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_TearDownTest) { | 2047 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_TearDownTest) { |
| 1958 const extensions::Extension* extension = | 2048 const extensions::Extension* extension = |
| 1959 LoadAndLaunchPlatformApp("web_view/teardown", "guest-loaded"); | 2049 LoadAndLaunchPlatformApp("web_view/simple", "WebViewTest.LAUNCHED"); |
| 1960 extensions::AppWindow* window = NULL; | 2050 extensions::AppWindow* window = NULL; |
| 1961 if (!GetAppWindowCount()) | 2051 if (!GetAppWindowCount()) |
| 1962 window = CreateAppWindow(extension); | 2052 window = CreateAppWindow(extension); |
| 1963 else | 2053 else |
| 1964 window = GetFirstAppWindow(); | 2054 window = GetFirstAppWindow(); |
| 1965 CloseAppWindow(window); | 2055 CloseAppWindow(window); |
| 1966 | 2056 |
| 1967 // Load the app again. | 2057 // Load the app again. |
| 1968 LoadAndLaunchPlatformApp("web_view/teardown", "guest-loaded"); | 2058 LoadAndLaunchPlatformApp("web_view/simple", "WebViewTest.LAUNCHED"); |
| 1969 } | 2059 } |
| 1970 | 2060 |
| 1971 // In following GeolocationAPIEmbedderHasNoAccess* tests, embedder (i.e. the | 2061 // In following GeolocationAPIEmbedderHasNoAccess* tests, embedder (i.e. the |
| 1972 // platform app) does not have geolocation permission for this test. | 2062 // platform app) does not have geolocation permission for this test. |
| 1973 // No matter what the API does, geolocation permission would be denied. | 2063 // No matter what the API does, geolocation permission would be denied. |
| 1974 // Note that the test name prefix must be "GeolocationAPI". | 2064 // Note that the test name prefix must be "GeolocationAPI". |
| 1975 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasNoAccessAllow) { | 2065 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasNoAccessAllow) { |
| 1976 TestHelper("testDenyDenies", | 2066 TestHelper("testDenyDenies", |
| 1977 "web_view/geolocation/embedder_has_no_permission", | 2067 "web_view/geolocation/embedder_has_no_permission", |
| 1978 NEEDS_TEST_SERVER); | 2068 NEEDS_TEST_SERVER); |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2475 // http://crbug.com/403325 | 2565 // http://crbug.com/403325 |
| 2476 #define MAYBE_WebViewInBackgroundPage \ | 2566 #define MAYBE_WebViewInBackgroundPage \ |
| 2477 DISABLED_WebViewInBackgroundPage | 2567 DISABLED_WebViewInBackgroundPage |
| 2478 #else | 2568 #else |
| 2479 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage | 2569 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage |
| 2480 #endif | 2570 #endif |
| 2481 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_WebViewInBackgroundPage) { | 2571 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_WebViewInBackgroundPage) { |
| 2482 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background")) | 2572 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background")) |
| 2483 << message_; | 2573 << message_; |
| 2484 } | 2574 } |
| OLD | NEW |