diff options
author | raymes <raymes@chromium.org> | 2015-01-05 20:16:03 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-06 04:16:52 +0000 |
commit | a2baa611bfba2ae510ba2af4e9e44ae5d6cdd160 (patch) | |
tree | c8b46348bb9a13228a20307bb0d213709d5a08a1 | |
parent | ec1f1c7f010d38beabcbbc653e0df4b299133c7a (diff) | |
download | chromium_src-a2baa611bfba2ae510ba2af4e9e44ae5d6cdd160.zip chromium_src-a2baa611bfba2ae510ba2af4e9e44ae5d6cdd160.tar.gz chromium_src-a2baa611bfba2ae510ba2af4e9e44ae5d6cdd160.tar.bz2 |
Add a test for MimeHandlerView postMessage
This adds a browser test for postMessage on MimeHandlerView. Messages are sent
to the guest and echoed back to the sender.
BUG=415858
Review URL: https://codereview.chromium.org/815673003
Cr-Commit-Position: refs/heads/master@{#310047}
9 files changed, 131 insertions, 2 deletions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 0ea1e58..6fc97b3 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -43,6 +43,7 @@ '../extensions/browser/app_window/app_window_browsertest.cc', '../extensions/browser/guest_view/extension_options/extension_options_apitest.cc', '../extensions/renderer/console_apitest.cc', + '../extensions/renderer/guest_view/mime_handler_view/mime_handler_view_browsertest.cc', '../extensions/renderer/script_context_browsertest.cc', 'app/chrome_command_ids.h', 'app/chrome_dll.rc', diff --git a/chrome/test/data/extensions/api_test/mime_handler_view/embedded.html b/chrome/test/data/extensions/api_test/mime_handler_view/embedded.html new file mode 100644 index 0000000..b5648d6 --- /dev/null +++ b/chrome/test/data/extensions/api_test/mime_handler_view/embedded.html @@ -0,0 +1,6 @@ +<html> +<body> +This is the embedded MIME type handler. +</body> +<script src="embedded.js"></script> +</html> diff --git a/chrome/test/data/extensions/api_test/mime_handler_view/embedded.js b/chrome/test/data/extensions/api_test/mime_handler_view/embedded.js new file mode 100644 index 0000000..6cb22a6 --- /dev/null +++ b/chrome/test/data/extensions/api_test/mime_handler_view/embedded.js @@ -0,0 +1,8 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +window.addEventListener('message', function(event) { + // Echo the data back to the source window. + event.source.postMessage(event.data, '*'); +}, false);
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/mime_handler_view/manifest.json b/chrome/test/data/extensions/api_test/mime_handler_view/manifest.json new file mode 100644 index 0000000..cc45c6f --- /dev/null +++ b/chrome/test/data/extensions/api_test/mime_handler_view/manifest.json @@ -0,0 +1,18 @@ +{ + "name": "Test MIMEHandlerView", + "version": "1", + "manifest_version": 2, + "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDJ8Hl8K6R+n/hrPsN1ienxRU3GbL00wFHLJNML45MHwT+3PstgWf4EgC3wbyyTXFtbvJC+Hn14Hyltfhsa+cSraldNHeL+rl+FL04kE4uYHq8YhOYEtzUfg380+o7XV9oESKu9oLTeG9QuQCjmlp3MUqC9wm7ICjxR9flODClOkQIDAQAB", + "mime_types": [ + "text/csv" + ], + "web_accessible_resources": [ + "test_postmessage.html", + "test_postmessage.js", + "test.csv" + ], + "mime_types_handler": "embedded.html", + "permissions": [ + "streamsPrivate" + ] +} diff --git a/chrome/test/data/extensions/api_test/mime_handler_view/test.csv b/chrome/test/data/extensions/api_test/mime_handler_view/test.csv new file mode 100644 index 0000000..2d025de --- /dev/null +++ b/chrome/test/data/extensions/api_test/mime_handler_view/test.csv @@ -0,0 +1 @@ +The data contained in this file is not important.
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/mime_handler_view/test_postmessage.html b/chrome/test/data/extensions/api_test/mime_handler_view/test_postmessage.html new file mode 100644 index 0000000..a2525f9 --- /dev/null +++ b/chrome/test/data/extensions/api_test/mime_handler_view/test_postmessage.html @@ -0,0 +1,6 @@ +<html> +<body> +<object id="plugin" width="200" height="200" data="chrome-extension://oickdpebdnfbgkcaoklfcdhjniefkcji/test.csv" type="text/csv"></object> +</body> +<script src="test_postmessage.js"></script> +</html> diff --git a/chrome/test/data/extensions/api_test/mime_handler_view/test_postmessage.js b/chrome/test/data/extensions/api_test/mime_handler_view/test_postmessage.js new file mode 100644 index 0000000..86103ecd --- /dev/null +++ b/chrome/test/data/extensions/api_test/mime_handler_view/test_postmessage.js @@ -0,0 +1,32 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var tests = [ + function testPostMessage() { + var messages = ['hey', 100, 25.0]; + var messages_sent = 0; + var messages_received = 0; + + window.addEventListener('message', function(event) { + if (event.data == messages[messages_received]) + messages_received++; + else + chrome.test.fail(); + + if (messages_received == messages.length) + chrome.test.succeed(); + }, false); + + var plugin = document.getElementById('plugin'); + function postNextMessage() { + plugin.postMessage(messages[messages_sent]); + messages_sent++; + if (messages_sent < messages.length) + setTimeout(postNextMessage, 0); + } + postNextMessage(); + }, +]; + +chrome.test.runTests(tests); diff --git a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_browsertest.cc b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_browsertest.cc new file mode 100644 index 0000000..bfb3e7c --- /dev/null +++ b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_browsertest.cc @@ -0,0 +1,53 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/base_paths.h" +#include "base/files/file_util.h" +#include "base/path_service.h" +#include "chrome/browser/extensions/extension_apitest.h" +#include "chrome/test/base/ui_test_utils.h" +#include "content/public/test/browser_test_utils.h" +#include "extensions/browser/extension_registry.h" +#include "extensions/test/result_catcher.h" + +// The test extension id is set by the key value in the manifest. +const char* kExtensionId = "oickdpebdnfbgkcaoklfcdhjniefkcji"; + +class MimeHandlerViewTest : public ExtensionApiTest { + public: + ~MimeHandlerViewTest() override {} + + const extensions::Extension* LoadTestExtension() { + const extensions::Extension* extension = LoadExtension( + test_data_dir_.AppendASCII("mime_handler_view")); + if (!extension) + return nullptr; + + CHECK_EQ(std::string(kExtensionId), extension->id()); + + return extension; + } +}; + +// Not working on Windows because of crbug.com/443466. +#if defined(OS_WIN) +#define MAYBE_PostMessage DISABLED_PostMessage +#else +#define MAYBE_PostMessage PostMessage +#endif + +IN_PROC_BROWSER_TEST_F(MimeHandlerViewTest, MAYBE_PostMessage) { + const extensions::Extension* extension = LoadTestExtension(); + ASSERT_TRUE(extension); + + extensions::ResultCatcher catcher; + + GURL extension_url("chrome-extension://" + + std::string(kExtensionId) + + "/test_postmessage.html"); + ui_test_utils::NavigateToURL(browser(), extension_url); + + if (!catcher.GetNextResult()) + FAIL() << catcher.message(); +} diff --git a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc index efddf2f..85f6930 100644 --- a/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc +++ b/extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc @@ -184,8 +184,11 @@ void MimeHandlerViewContainer::PostMessage(v8::Isolate* isolate, // should already know what is embedded. gin::StringToV8(isolate, "*") }; - post_message.As<v8::Function>()->Call( - guest_proxy_window, arraysize(args), args); + guest_proxy_frame->callFunctionEvenIfScriptDisabled( + post_message.As<v8::Function>(), + guest_proxy_window, + arraysize(args), + args); } void MimeHandlerViewContainer::OnCreateMimeHandlerViewGuestACK( @@ -228,6 +231,7 @@ void MimeHandlerViewContainer::CreateMimeHandlerViewGuest() { // Parse the stream URL to ensure it's valid. GURL stream_url(html_string_); + DCHECK(!stream_url.spec().empty()); DCHECK_NE(element_instance_id(), guestview::kInstanceIDNone); render_frame()->Send(new ExtensionHostMsg_CreateMimeHandlerViewGuest( |