blob: fef94500fdff173c7489039629d5c7f660c4fbca [file] [log] [blame]
[email protected]871dc682012-06-11 19:35:331// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]4af886ca2012-04-07 00:05:112// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]57999812013-02-24 05:40:525#include "base/files/file_path.h"
[email protected]112158af2013-06-07 23:46:186#include "base/strings/utf_string_conversions.h"
[email protected]4af886ca2012-04-07 00:05:117#include "chrome/browser/ui/browser.h"
[email protected]cc872372013-01-28 21:57:078#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]4af886ca2012-04-07 00:05:119#include "chrome/test/base/in_process_browser_test.h"
10#include "chrome/test/base/ui_test_utils.h"
naskof6a80ac2016-06-29 02:37:0511#include "content/public/browser/render_frame_host.h"
[email protected]4af886ca2012-04-07 00:05:1112#include "content/public/browser/web_contents.h"
naskof6a80ac2016-06-29 02:37:0513#include "content/public/test/browser_test_utils.h"
[email protected]761fa4702013-07-02 15:25:1514#include "url/gurl.h"
[email protected]4af886ca2012-04-07 00:05:1115
16class IFrameTest : public InProcessBrowserTest {
naskof6a80ac2016-06-29 02:37:0517 public:
18 void SetUpOnMainThread() override {
19 ASSERT_TRUE(embedded_test_server()->Start());
20 }
21
[email protected]4af886ca2012-04-07 00:05:1122 protected:
23 void NavigateAndVerifyTitle(const char* file, const char* page_title) {
24 GURL url = ui_test_utils::GetTestUrl(
[email protected]650b2d52013-02-10 03:41:4525 base::FilePath(), base::FilePath().AppendASCII(file));
[email protected]4af886ca2012-04-07 00:05:1126
27 ui_test_utils::NavigateToURL(browser(), url);
[email protected]04338722013-12-24 23:18:0528 EXPECT_EQ(base::ASCIIToUTF16(page_title),
[email protected]cc872372013-01-28 21:57:0729 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
[email protected]4af886ca2012-04-07 00:05:1130 }
31};
32
33IN_PROC_BROWSER_TEST_F(IFrameTest, Crash) {
34 NavigateAndVerifyTitle("iframe.html", "iframe test");
35}
36
37IN_PROC_BROWSER_TEST_F(IFrameTest, InEmptyFrame) {
38 NavigateAndVerifyTitle("iframe_in_empty_frame.html", "iframe test");
39}
naskof6a80ac2016-06-29 02:37:0540
41// Test for https://crbug.com/621076. It ensures that file chooser triggered
42// by an iframe, which is destroyed before the chooser is closed, does not
43// result in a use-after-free condition.
44// Note: This test is disabled temporarily to track down a memory leak reported
45// by the ASan bots. It will be enabled once the root cause is found.
46IN_PROC_BROWSER_TEST_F(IFrameTest, DISABLED_FileChooserInDestroyedSubframe) {
47 content::WebContents* tab =
48 browser()->tab_strip_model()->GetActiveWebContents();
49 GURL file_input_url(embedded_test_server()->GetURL("/file_input.html"));
50
51 // Navigate to a page, which contains an iframe, and navigate the iframe
52 // to a document containing a file input field.
53 // Note: For the bug to occur, the parent and child frame need to be in
54 // the same site, otherwise they would each get a RenderWidgetHost and
55 // existing code will properly clear the internal state.
56 ui_test_utils::NavigateToURL(browser(),
57 embedded_test_server()->GetURL("/iframe.html"));
58 NavigateIframeToURL(tab, "test", file_input_url);
59
60 // Invoke the file chooser and remove the iframe from the main document.
61 content::RenderFrameHost* frame = ChildFrameAt(tab->GetMainFrame(), 0);
62 EXPECT_TRUE(frame);
63 EXPECT_EQ(frame->GetSiteInstance(), tab->GetMainFrame()->GetSiteInstance());
64 EXPECT_TRUE(
65 ExecuteScript(frame, "document.getElementById('fileinput').click();"));
66 EXPECT_TRUE(ExecuteScript(tab->GetMainFrame(),
67 "document.body.removeChild("
68 "document.querySelectorAll('iframe')[0])"));
69 ASSERT_EQ(nullptr, ChildFrameAt(tab->GetMainFrame(), 0));
70
71 // On ASan bots, this test should succeed without reporting use-after-free
72 // condition.
73}