Merge revision 1085 changes:

- Add a new CefLifeSpanHandler::CanCreatePopup() method for canceling the creation of popup windows (issue #816).

git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1364@1086 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2013-02-08 00:11:14 +00:00
parent c73e3e12a9
commit 49fc452cd5
13 changed files with 424 additions and 91 deletions

View File

@@ -4,6 +4,7 @@
#include <list>
#include "include/cef_callback.h"
#include "include/cef_runnable.h"
#include "include/cef_scheme.h"
#include "tests/cefclient/client_app.h"
#include "tests/unittests/test_handler.h"
@@ -1440,6 +1441,116 @@ TEST(NavigationTest, CrossOrigin) {
}
namespace {
const char kPopupNavPageUrl[] = "http://tests-popup/page.html";
const char kPopupNavPopupUrl[] = "http://tests-popup/popup.html";
const char kPopupNavPopupName[] = "my_popup";
// Browser side.
class PopupNavTestHandler : public TestHandler {
public:
explicit PopupNavTestHandler(bool allow)
: allow_(allow) {}
virtual void RunTest() OVERRIDE {
// Add the resources that we will navigate to/from.
std::string page = "<html><script>window.open('" +
std::string(kPopupNavPopupUrl) + "', '" +
std::string(kPopupNavPopupName) +
"');</script></html>";
AddResource(kPopupNavPageUrl, page, "text/html");
AddResource(kPopupNavPopupUrl, "<html>Popup</html>", "text/html");
// Create the browser.
CreateBrowser(kPopupNavPageUrl);
}
virtual bool CanCreatePopup(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& target_url,
const CefString& target_frame_name,
bool* no_javascript_access) OVERRIDE {
got_can_create_popup_.yes();
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
EXPECT_STREQ(kPopupNavPageUrl, frame->GetURL().ToString().c_str());
EXPECT_STREQ(kPopupNavPopupUrl, target_url.ToString().c_str());
EXPECT_STREQ(kPopupNavPopupName, target_frame_name.ToString().c_str());
EXPECT_FALSE(*no_javascript_access);
return allow_;
}
virtual void OnBeforePopup(CefRefPtr<CefBrowser> browser,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
const CefString& target_url,
const CefString& target_frame_name,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings) OVERRIDE {
got_on_before_popup_.yes();
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
EXPECT_EQ(GetBrowserId(), browser->GetIdentifier());
EXPECT_STREQ(kPopupNavPopupUrl, target_url.ToString().c_str());
EXPECT_STREQ(kPopupNavPopupName, target_frame_name.ToString().c_str());
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE {
std::string url = frame->GetURL();
if (allow_) {
if (url == kPopupNavPopupUrl) {
got_popup_load_end_.yes();
browser->GetHost()->CloseBrowser();
DestroyTest();
}
} else {
// Wait a bit to make sure the popup window isn't created.
CefPostDelayedTask(TID_UI,
NewCefRunnableMethod(this, &PopupNavTestHandler::DestroyTest), 200);
}
}
private:
virtual void DestroyTest() {
EXPECT_TRUE(got_can_create_popup_);
if (allow_) {
EXPECT_TRUE(got_on_before_popup_);
EXPECT_TRUE(got_popup_load_end_);
} else {
EXPECT_FALSE(got_on_before_popup_);
EXPECT_FALSE(got_popup_load_end_);
}
TestHandler::DestroyTest();
}
bool allow_;
TrackCallback got_can_create_popup_;
TrackCallback got_on_before_popup_;
TrackCallback got_popup_load_end_;
};
} // namespace
// Test allowing popups.
TEST(NavigationTest, PopupAllow) {
CefRefPtr<PopupNavTestHandler> handler = new PopupNavTestHandler(true);
handler->ExecuteTest();
}
// Test denying popups.
TEST(NavigationTest, PopupDeny) {
CefRefPtr<PopupNavTestHandler> handler = new PopupNavTestHandler(false);
handler->ExecuteTest();
}
// Entry point for creating navigation browser test objects.
// Called from client_app_delegates.cc.
void CreateNavigationBrowserTests(ClientApp::BrowserDelegateSet& delegates) {