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

Unified Diff: content/browser/loader/buffered_resource_handler_unittest.cc

Issue 953793003: Ensuring interception of stream get determined by plugin path before checking mime type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changing Test Cases. Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/loader/buffered_resource_handler_unittest.cc
diff --git a/content/browser/loader/buffered_resource_handler_unittest.cc b/content/browser/loader/buffered_resource_handler_unittest.cc
index 97b9668c88c5cbfaba4bb1e6427e781733623761..3d9b219628854ec8b8b8a44c231aba42261f63ca 100644
--- a/content/browser/loader/buffered_resource_handler_unittest.cc
+++ b/content/browser/loader/buffered_resource_handler_unittest.cc
@@ -12,6 +12,7 @@
#include "content/public/browser/resource_dispatcher_host_delegate.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/common/resource_response.h"
+#include "content/public/common/webplugininfo.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_utils.h"
#include "content/test/fake_plugin_service.h"
@@ -99,6 +100,7 @@ class TestResourceDispatcherHost : public ResourceDispatcherHostImpl {
}
scoped_ptr<ResourceHandler> MaybeInterceptAsStream(
+ const base::FilePath& plugin_path,
net::URLRequest* request,
ResourceResponse* response,
std::string* payload) override {
@@ -151,14 +153,57 @@ class TestResourceController : public ResourceController {
}
};
+class TestFakePluginService : public FakePluginService {
+ public:
+ TestFakePluginService(bool fake_plugin_available)
raymes 2015/03/24 03:01:49 nit: plugin_available is fine
jochen (gone - plz use gerrit) 2015/03/24 09:20:54 explicit
Deepak 2015/03/24 10:33:46 Done.
Deepak 2015/03/24 10:33:46 Done.
+ : fake_plugin_available_(fake_plugin_available) {}
+ bool GetPluginInfo(int render_process_id,
+ int render_frame_id,
+ ResourceContext* context,
+ const GURL& url,
+ const GURL& page_url,
+ const std::string& mime_type,
+ bool allow_wildcard,
+ bool* is_stale,
+ WebPluginInfo* info,
+ std::string* actual_mime_type) override;
+
+ private:
+ bool fake_plugin_available_;
+};
jochen (gone - plz use gerrit) 2015/03/24 09:20:54 DISALLOW_COPY_AND_ASSIGN()
Deepak 2015/03/24 10:33:46 Done.
+
+bool TestFakePluginService::GetPluginInfo(int render_process_id,
+ int render_frame_id,
+ ResourceContext* context,
+ const GURL& url,
+ const GURL& page_url,
+ const std::string& mime_type,
+ bool allow_wildcard,
+ bool* is_stale,
+ WebPluginInfo* info,
+ std::string* actual_mime_type) {
+ *is_stale = false;
+ if (!fake_plugin_available_)
+ return false;
+ info->type = WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN;
+ info->path = base::FilePath(
+ std::string("chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/"));
+ return true;
+}
+
class BufferedResourceHandlerTest : public testing::Test {
public:
- BufferedResourceHandlerTest() : stream_has_handler_(false) {}
+ BufferedResourceHandlerTest()
+ : stream_has_handler_(false), plugin_available_(false) {}
void set_stream_has_handler(bool stream_has_handler) {
stream_has_handler_ = stream_has_handler;
}
+ void set_plugin_available(bool plugin_available) {
+ plugin_available_ = plugin_available;
+ }
+
bool TestStreamIsIntercepted(bool allow_download,
bool must_download,
ResourceType request_resource_type);
@@ -166,6 +211,7 @@ class BufferedResourceHandlerTest : public testing::Test {
private:
// Whether the URL request should be intercepted as a stream.
bool stream_has_handler_;
+ bool plugin_available_;
TestBrowserThreadBundle thread_bundle_;
};
@@ -194,7 +240,7 @@ bool BufferedResourceHandlerTest::TestStreamIsIntercepted(
TestResourceDispatcherHostDelegate host_delegate(must_download);
host.SetDelegate(&host_delegate);
- FakePluginService plugin_service;
+ TestFakePluginService plugin_service(plugin_available_);
scoped_ptr<ResourceHandler> buffered_handler(
new BufferedResourceHandler(
scoped_ptr<ResourceHandler>(new TestResourceHandler()).Pass(),
@@ -227,6 +273,7 @@ TEST_F(BufferedResourceHandlerTest, StreamHandling) {
// ResourceDispatcherHost.
set_stream_has_handler(true);
+ set_plugin_available(true);
// Main frame request with no download allowed. Stream shouldn't be
// intercepted.
allow_download = false;
@@ -279,6 +326,16 @@ TEST_F(BufferedResourceHandlerTest, StreamHandling) {
resource_type = RESOURCE_TYPE_MAIN_FRAME;
EXPECT_FALSE(
TestStreamIsIntercepted(allow_download, must_download, resource_type));
+
+ // Test the cases where the stream handled by MaybeInterceptAsStream
+ // with plugin not available.
raymes 2015/03/24 03:01:49 nit: add to the comment: "This is the case when in
Deepak 2015/03/24 10:33:46 Done.
+ set_stream_has_handler(true);
+ allow_download = false;
+ must_download = false;
+ resource_type = RESOURCE_TYPE_OBJECT;
+ set_plugin_available(false);
+ EXPECT_TRUE(
+ TestStreamIsIntercepted(allow_download, must_download, resource_type));
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698