Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: third_party/WebKit/Source/web/tests/WebFrameTest.cpp

Issue 1816983002: Add a setting to allow window object reuse across a top-level initial navigation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 8487 matching lines...) Expand 10 before | Expand all | Expand 10 after
8498 EXPECT_TRUE(remoteFrameClient()->isVisible()); 8498 EXPECT_TRUE(remoteFrameClient()->isVisible());
8499 } 8499 }
8500 8500
8501 TEST_F(WebFrameVisibilityChangeTest, RemoteFrameParentVisibilityChange) 8501 TEST_F(WebFrameVisibilityChangeTest, RemoteFrameParentVisibilityChange)
8502 { 8502 {
8503 swapLocalFrameToRemoteFrame(); 8503 swapLocalFrameToRemoteFrame();
8504 executeScriptOnMainFrame(WebScriptSource("document.querySelector('iframe').p arentElement.style.display = 'none';")); 8504 executeScriptOnMainFrame(WebScriptSource("document.querySelector('iframe').p arentElement.style.display = 'none';"));
8505 EXPECT_FALSE(remoteFrameClient()->isVisible()); 8505 EXPECT_FALSE(remoteFrameClient()->isVisible());
8506 } 8506 }
8507 8507
8508 static void enableGlobalReuseForUnownedMainFrames(WebSettings* settings)
8509 {
8510 settings->setShouldReuseGlobalForUnownedMainFrame(true);
8511 }
8512
8513 // A main frame with no opener should have a unique security origin. Thus, the
8514 // global should never be reused on the initial navigation.
8515 TEST(WebFrameGlobalReuseTest, MainFrameWithNoOpener)
8516 {
8517 FrameTestHelpers::WebViewHelper helper;
8518 helper.initialize(true);
8519
8520 WebLocalFrame* mainFrame = helper.webView()->mainFrame()->toWebLocalFrame();
8521 v8::HandleScope scope(v8::Isolate::GetCurrent());
8522 mainFrame->executeScript(WebScriptSource("hello = 'world';"));
8523 FrameTestHelpers::loadFrame(mainFrame, "data:text/html,new page");
8524 v8::Local<v8::Value> result = mainFrame->executeScriptAndReturnValue(WebScri ptSource("hello"));
8525 EXPECT_TRUE(result.IsEmpty());
8526 }
8527
8528 // Child frames should never reuse the global on a cross-origin navigation, even
8529 // if the setting is enabled. It's not safe to since the parent could have
8530 // injected script before the initial navigation.
8531 TEST(WebFrameGlobalReuseTest, ChildFrame)
8532 {
8533 FrameTestHelpers::WebViewHelper helper;
8534 helper.initialize(true, nullptr, nullptr, enableGlobalReuseForUnownedMainFra mes);
8535
8536 WebLocalFrame* mainFrame = helper.webView()->mainFrame()->toWebLocalFrame();
8537 FrameTestHelpers::loadFrame(mainFrame, "data:text/html,<iframe></iframe>");
8538
8539 WebLocalFrame* childFrame = mainFrame->firstChild()->toWebLocalFrame();
8540 v8::HandleScope scope(v8::Isolate::GetCurrent());
8541 childFrame->executeScript(WebScriptSource("hello = 'world';"));
8542 FrameTestHelpers::loadFrame(childFrame, "data:text/html,new page");
8543 v8::Local<v8::Value> result = childFrame->executeScriptAndReturnValue(WebScr iptSource("hello"));
8544 EXPECT_TRUE(result.IsEmpty());
8545 }
8546
8547 // A main frame with an opener should never reuse the global on a cross-origin
8548 // navigation, even if the setting is enabled. It's not safe to since the opener
8549 // could have injected script.
8550 TEST(WebFrameGlobalReuseTest, MainFrameWithOpener)
8551 {
8552 FrameTestHelpers::TestWebViewClient openerWebViewClient;
8553 FrameTestHelpers::WebViewHelper openerHelper;
8554 openerHelper.initialize(false, nullptr, &openerWebViewClient);
8555 FrameTestHelpers::WebViewHelper helper;
8556 helper.initializeWithOpener(openerHelper.webView()->mainFrame(), true, nullp tr, nullptr, enableGlobalReuseForUnownedMainFrames);
8557
8558 WebLocalFrame* mainFrame = helper.webView()->mainFrame()->toWebLocalFrame();
8559 v8::HandleScope scope(v8::Isolate::GetCurrent());
8560 mainFrame->executeScript(WebScriptSource("hello = 'world';"));
8561 FrameTestHelpers::loadFrame(mainFrame, "data:text/html,new page");
8562 v8::Local<v8::Value> result = mainFrame->executeScriptAndReturnValue(WebScri ptSource("hello"));
8563 EXPECT_TRUE(result.IsEmpty());
8564 }
8565
8566 // A main frame that is unrelated to any other frame /can/ reuse the global if
8567 // the setting is enabled. In this case, it's impossible for any other frames to
8568 // have touched the global. Only the embedder could have injected script, and
8569 // the embedder enabling this setting is a signal that the injected script needs
8570 // to persist on the first navigation away from the initial empty document.
8571 TEST(WebFrameGlobalReuseTest, ReuseForMainFrameIfEnabled)
8572 {
8573 FrameTestHelpers::WebViewHelper helper;
8574 helper.initialize(true, nullptr, nullptr, enableGlobalReuseForUnownedMainFra mes);
8575
8576 WebLocalFrame* mainFrame = helper.webView()->mainFrame()->toWebLocalFrame();
8577 v8::HandleScope scope(v8::Isolate::GetCurrent());
8578 mainFrame->executeScript(WebScriptSource("hello = 'world';"));
8579 FrameTestHelpers::loadFrame(mainFrame, "data:text/html,new page");
8580 v8::Local<v8::Value> result = mainFrame->executeScriptAndReturnValue(WebScri ptSource("hello"));
8581 ASSERT_TRUE(result->IsString());
8582 EXPECT_EQ("world", toCoreString(result->ToString(mainFrame->mainWorldScriptC ontext()).ToLocalChecked()));
8583 }
8584
8508 } // namespace blink 8585 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebSettingsImpl.cpp ('k') | third_party/WebKit/public/web/WebSettings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698