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

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

Issue 1081013002: Revert of 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: Created 5 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 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 51be31a8f325ec5dfe136ffedf1d963a9bfba435..e4d3668c371ff059657b48868c2a574c6f97dd13 100644
--- a/content/browser/loader/buffered_resource_handler_unittest.cc
+++ b/content/browser/loader/buffered_resource_handler_unittest.cc
@@ -4,7 +4,6 @@
#include "content/browser/loader/buffered_resource_handler.h"
-#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
@@ -13,7 +12,6 @@
#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"
@@ -86,8 +84,7 @@
public:
explicit TestResourceDispatcherHost(bool stream_has_handler)
: stream_has_handler_(stream_has_handler),
- intercepted_as_stream_(false),
- intercepted_as_stream_count_(0) {}
+ intercepted_as_stream_(false) {}
bool intercepted_as_stream() const { return intercepted_as_stream_; }
@@ -102,11 +99,9 @@
}
scoped_ptr<ResourceHandler> MaybeInterceptAsStream(
- const base::FilePath& plugin_path,
net::URLRequest* request,
ResourceResponse* response,
std::string* payload) override {
- intercepted_as_stream_count_++;
if (stream_has_handler_) {
intercepted_as_stream_ = true;
return scoped_ptr<ResourceHandler>(new TestResourceHandler).Pass();
@@ -115,20 +110,12 @@
}
}
- int intercepted_as_stream_count() const {
- return intercepted_as_stream_count_;
- }
-
private:
// Whether the URL request should be intercepted as a stream.
bool stream_has_handler_;
// Whether the URL request has been intercepted as a stream.
bool intercepted_as_stream_;
-
- // Count of number of times MaybeInterceptAsStream function get called in a
- // test.
- int intercepted_as_stream_count_;
};
class TestResourceDispatcherHostDelegate
@@ -164,63 +151,13 @@
}
};
-class TestFakePluginService : public FakePluginService {
- public:
- // If |is_plugin_stale| is true, GetPluginInfo will indicate the plugins are
- // stale until GetPlugins is called.
- TestFakePluginService(bool plugin_available, bool is_plugin_stale)
- : plugin_available_(plugin_available),
- is_plugin_stale_(is_plugin_stale) {}
-
- 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 {
- *is_stale = is_plugin_stale_;
- if (!is_plugin_stale_ || !plugin_available_)
- return false;
- info->type = WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN;
- info->path = base::FilePath::FromUTF8Unsafe(
- std::string("chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/"));
- return true;
- }
-
- void GetPlugins(const GetPluginsCallback& callback) override {
- is_plugin_stale_ = false;
- std::vector<WebPluginInfo> plugins;
- base::MessageLoop::current()->PostTask(FROM_HERE,
- base::Bind(callback, plugins));
- }
-
- private:
- const bool plugin_available_;
- bool is_plugin_stale_;
-
- DISALLOW_COPY_AND_ASSIGN(TestFakePluginService);
-};
-
class BufferedResourceHandlerTest : public testing::Test {
public:
- BufferedResourceHandlerTest()
- : stream_has_handler_(false),
- plugin_available_(false),
- plugin_stale_(false) {}
+ BufferedResourceHandlerTest() : stream_has_handler_(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;
- }
-
- void set_plugin_stale(bool plugin_stale) { plugin_stale_ = plugin_stale; }
bool TestStreamIsIntercepted(bool allow_download,
bool must_download,
@@ -229,8 +166,6 @@
private:
// Whether the URL request should be intercepted as a stream.
bool stream_has_handler_;
- bool plugin_available_;
- bool plugin_stale_;
TestBrowserThreadBundle thread_bundle_;
};
@@ -259,7 +194,7 @@
TestResourceDispatcherHostDelegate host_delegate(must_download);
host.SetDelegate(&host_delegate);
- TestFakePluginService plugin_service(plugin_available_, plugin_stale_);
+ FakePluginService plugin_service;
scoped_ptr<ResourceHandler> buffered_handler(
new BufferedResourceHandler(
scoped_ptr<ResourceHandler>(new TestResourceHandler()).Pass(),
@@ -277,13 +212,12 @@
buffered_handler->OnResponseStarted(response.get(), &defer);
content::RunAllPendingInMessageLoop();
- EXPECT_LT(host.intercepted_as_stream_count(), 2);
+
return host.intercepted_as_stream();
}
// Test that stream requests are correctly intercepted under the right
-// circumstances. Test is not relevent when plugins are disabled.
-#if defined(ENABLE_PLUGINS)
+// circumstances.
TEST_F(BufferedResourceHandlerTest, StreamHandling) {
bool allow_download;
bool must_download;
@@ -292,7 +226,6 @@
// Ensure the stream is handled by MaybeInterceptAsStream in the
// ResourceDispatcherHost.
set_stream_has_handler(true);
- set_plugin_available(true);
// Main frame request with no download allowed. Stream shouldn't be
// intercepted.
@@ -334,6 +267,7 @@
// Test the cases where the stream isn't handled by MaybeInterceptAsStream
// in the ResourceDispatcherHost.
set_stream_has_handler(false);
+
allow_download = false;
must_download = false;
resource_type = RESOURCE_TYPE_OBJECT;
@@ -345,29 +279,7 @@
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. This is the case when intercepting streams for
- // the streamsPrivate extensions API.
- set_stream_has_handler(true);
- set_plugin_available(false);
- allow_download = false;
- must_download = false;
- resource_type = RESOURCE_TYPE_OBJECT;
- EXPECT_TRUE(
- TestStreamIsIntercepted(allow_download, must_download, resource_type));
-
- // Test the cases where the stream handled by MaybeInterceptAsStream
- // with plugin not available. This is the case when intercepting streams for
- // the streamsPrivate extensions API with stale plugin.
- set_plugin_stale(true);
- allow_download = false;
- must_download = false;
- resource_type = RESOURCE_TYPE_OBJECT;
- EXPECT_TRUE(
- TestStreamIsIntercepted(allow_download, must_download, resource_type));
}
-#endif
} // namespace
« no previous file with comments | « content/browser/loader/buffered_resource_handler.cc ('k') | content/browser/loader/resource_dispatcher_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698