OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
9 #include "content/public/browser/web_contents_delegate.h" | 9 #include "content/public/browser/web_contents_delegate.h" |
10 #include "content/public/test/browser_test_utils.h" | 10 #include "content/public/test/browser_test_utils.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 web_contents->SetDelegate(old_delegate); | 66 web_contents->SetDelegate(old_delegate); |
67 return close_tracking_delegate.close_contents_called(); | 67 return close_tracking_delegate.close_contents_called(); |
68 } | 68 } |
69 | 69 |
70 Shell* OpenWindowFromJavaScript(Shell* shell, const GURL& url) { | 70 Shell* OpenWindowFromJavaScript(Shell* shell, const GURL& url) { |
71 // Wait for the popup to be created and for it to have navigated. | 71 // Wait for the popup to be created and for it to have navigated. |
72 ShellAddedObserver new_shell_observer; | 72 ShellAddedObserver new_shell_observer; |
73 TestNavigationObserver nav_observer(NULL); | 73 TestNavigationObserver nav_observer(NULL); |
74 nav_observer.StartWatchingNewWebContents(); | 74 nav_observer.StartWatchingNewWebContents(); |
75 CHECK(ExecuteScript( | 75 CHECK(ExecuteScript( |
76 shell->web_contents(), | 76 shell, base::StringPrintf("window.open('%s')", url.spec().c_str()))); |
77 base::StringPrintf("window.open('%s')", url.spec().c_str()))); | |
78 nav_observer.Wait(); | 77 nav_observer.Wait(); |
79 return new_shell_observer.GetShell(); | 78 return new_shell_observer.GetShell(); |
80 } | 79 } |
81 }; | 80 }; |
82 | 81 |
83 // Tests that window.close() does not work on a normal window that has navigated | 82 // Tests that window.close() does not work on a normal window that has navigated |
84 // a few times. | 83 // a few times. |
85 IN_PROC_BROWSER_TEST_F(OpenedByDOMTest, NormalWindow) { | 84 IN_PROC_BROWSER_TEST_F(OpenedByDOMTest, NormalWindow) { |
86 ASSERT_TRUE(embedded_test_server()->Start()); | 85 ASSERT_TRUE(embedded_test_server()->Start()); |
87 | 86 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 url3 = url3.ReplaceComponents(replace_host); | 128 url3 = url3.ReplaceComponents(replace_host); |
130 | 129 |
131 NavigateToURL(shell(), url1); | 130 NavigateToURL(shell(), url1); |
132 | 131 |
133 Shell* popup = OpenWindowFromJavaScript(shell(), url2); | 132 Shell* popup = OpenWindowFromJavaScript(shell(), url2); |
134 NavigateToURL(popup, url3); | 133 NavigateToURL(popup, url3); |
135 EXPECT_TRUE(AttemptCloseFromJavaScript(popup->web_contents())); | 134 EXPECT_TRUE(AttemptCloseFromJavaScript(popup->web_contents())); |
136 } | 135 } |
137 | 136 |
138 } // namespace content | 137 } // namespace content |
OLD | NEW |