#include "content/public/common/resource_type.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h"
+#include "content/test/test_render_view_host_factory.h"
#include "content/test/test_web_contents.h"
#include "net/base/host_port_pair.h"
#include "net/base/request_priority.h"
url_request_(url_request.Pass()) {
throttle_->set_controller_for_testing(this);
}
- virtual ~TestRequest() {}
+ ~TestRequest() override {}
bool started() const { return started_; }
started_ = !deferred;
}
- virtual void Cancel() OVERRIDE {
+ void Cancel() override {
// Alert the scheduler that the request can be deleted.
throttle_.reset(0);
}
protected:
// ResourceController interface:
- virtual void CancelAndIgnore() OVERRIDE {}
- virtual void CancelWithError(int error_code) OVERRIDE {}
- virtual void Resume() OVERRIDE { started_ = true; }
+ void CancelAndIgnore() override {}
+ void CancelWithError(int error_code) override {}
+ void Resume() override { started_ = true; }
private:
bool started_;
}
private:
- virtual void Resume() OVERRIDE {
+ void Resume() override {
TestRequest::Resume();
request_to_cancel_.reset();
}
class FakeResourceContext : public ResourceContext {
private:
- virtual net::HostResolver* GetHostResolver() OVERRIDE { return NULL; }
- virtual net::URLRequestContext* GetRequestContext() OVERRIDE { return NULL; }
+ net::HostResolver* GetHostResolver() override { return NULL; }
+ net::URLRequestContext* GetRequestContext() override { return NULL; }
};
class FakeResourceMessageFilter : public ResourceMessageFilter {
}
private:
- virtual ~FakeResourceMessageFilter() {}
+ ~FakeResourceMessageFilter() override {}
void GetContexts(const ResourceHostMsg_Request& request,
ResourceContext** resource_context,
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
false /* should_coalesce */);
- scheduler_.OnClientCreated(kChildId, kRouteId, true);
- scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId, false);
+ scheduler_.OnClientCreated(kChildId, kRouteId, true, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId, kBackgroundRouteId, false, false);
context_.set_http_server_properties(http_server_properties_.GetWeakPtr());
}
- virtual ~ResourceSchedulerTest() {
+ ~ResourceSchedulerTest() override {
scheduler_.OnClientDeleted(kChildId, kRouteId);
scheduler_.OnClientDeleted(kBackgroundChildId, kBackgroundRouteId);
}
true, // allow_download
false, // has_user_gesture
false, // enable_load_timing
+ false, // enable_upload_progress
blink::WebReferrerPolicyDefault, // referrer_policy
blink::WebPageVisibilityStateVisible, // visibility_state
NULL, // context
EXPECT_TRUE(low2->started());
}
+TEST_F(ResourceSchedulerTest, LowDoesNotBlockCriticalComplete) {
+ scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOW));
+ scoped_ptr<TestRequest> lowest(NewRequest("http://host/lowest", net::LOWEST));
+ scoped_ptr<TestRequest> lowest2(
+ NewRequest("http://host/lowest", net::LOWEST));
+ EXPECT_TRUE(low->started());
+ EXPECT_TRUE(lowest->started());
+ EXPECT_FALSE(lowest2->started());
+ scheduler_.OnWillInsertBody(kChildId, kRouteId);
+ EXPECT_TRUE(lowest2->started());
+}
+
TEST_F(ResourceSchedulerTest, OneLowLoadsUntilBodyInsertedExceptSpdy) {
http_server_properties_.SetSupportsSpdy(
net::HostPortPair("spdyhost", 443), true);
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
false /* should_coalesce */);
EXPECT_TRUE(scheduler_.should_throttle());
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
EXPECT_EQ(ResourceScheduler::THROTTLED,
scheduler_.GetClientStateForTesting(kBackgroundChildId2,
// TODO(aiolos): remove when throttling and coalescing have both landed
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
false /* should_coalesce */);
- scheduler_.OnClientCreated(kChildId2, kRouteId2, false);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(kChildId2, kRouteId2, false, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
scheduler_.OnLoadingStateChanged(
kBackgroundChildId2, kBackgroundRouteId2, true);
// TODO(aiolos): remove when throttling and coalescing have both landed
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
false /* should_coalesce */);
- scheduler_.OnClientCreated(kChildId2, kRouteId2, false);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(kChildId2, kRouteId2, false, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
scheduler_.OnLoadingStateChanged(
kBackgroundChildId2, kBackgroundRouteId2, true);
scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
// TODO(aiolos): remove when throttling and coalescing have both landed
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
false /* should_coalesce */);
- scheduler_.OnClientCreated(kChildId2, kRouteId2, false);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(kChildId2, kRouteId2, false, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
scheduler_.OnLoadingStateChanged(
kBackgroundChildId2, kBackgroundRouteId2, true);
// TODO(aiolos): remove when throttling and coalescing have both landed
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
false /* should_coalesce */);
- scheduler_.OnClientCreated(kChildId2, kRouteId2, false);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(kChildId2, kRouteId2, false, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
scheduler_.OnLoadingStateChanged(
kBackgroundChildId2, kBackgroundRouteId2, true);
// TODO(aiolos): remove when throttling and coalescing have both landed
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
false /* should_coalesce */);
- scheduler_.OnClientCreated(kChildId2, kRouteId2, true);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
scheduler_.OnLoadingStateChanged(
kBackgroundChildId2, kBackgroundRouteId2, true);
// TODO(aiolos): remove when throttling and coalescing have both landed
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
false /* should_coalesce */);
- scheduler_.OnClientCreated(kChildId2, kRouteId2, false);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(kChildId2, kRouteId2, false, true);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
scheduler_.OnLoadingStateChanged(
kBackgroundChildId2, kBackgroundRouteId2, true);
scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
- scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true);
// 2 audible, 2 hidden
EXPECT_FALSE(scheduler_.active_clients_loaded());
EXPECT_EQ(ResourceScheduler::THROTTLED,
// TODO(aiolos): remove when throttling and coalescing have both landed
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
false /* should_coalesce */);
- scheduler_.OnClientCreated(kChildId2, kRouteId2, true);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
scheduler_.OnLoadingStateChanged(
kBackgroundChildId2, kBackgroundRouteId2, true);
scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
// TODO(aiolos): remove when throttling and coalescing have both landed
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
false /* should_coalesce */);
- scheduler_.OnClientCreated(kChildId2, kRouteId2, false);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(kChildId2, kRouteId2, false, true);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
scheduler_.OnLoadingStateChanged(
kBackgroundChildId2, kBackgroundRouteId2, true);
scheduler_.OnLoadingStateChanged(kChildId2, kRouteId2, true);
scheduler_.OnVisibilityChanged(kChildId, kRouteId, false);
scheduler_.OnAudibilityChanged(kChildId, kRouteId, true);
- scheduler_.OnAudibilityChanged(kChildId2, kRouteId2, true);
// 2 audible, 2 hidden
EXPECT_FALSE(scheduler_.active_clients_loaded());
EXPECT_EQ(ResourceScheduler::THROTTLED,
// TODO(aiolos): remove when throttling and coalescing have both landed
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
false /* should_coalesce */);
- scheduler_.OnClientCreated(kChildId2, kRouteId2, true);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
// 1 visible and 2 hidden loading, 1 visible loaded
scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
// TODO(aiolos): remove when throttling and coalescing have both landed
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
false /* should_coalesce */);
- scheduler_.OnClientCreated(kChildId2, kRouteId2, true);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
// 2 visible loading, 1 hidden loading, 1 hidden loaded
scheduler_.OnLoadingStateChanged(
// TODO(aiolos): remove when throttling and coalescing have both landed
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
false /* should_coalesce */);
- scheduler_.OnClientCreated(kChildId2, kRouteId2, true);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
// 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading
scheduler_.OnLoadingStateChanged(
// TODO(aiolos): remove when throttling and coalescing have both landed
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
false /* should_coalesce */);
- scheduler_.OnClientCreated(kChildId2, kRouteId2, true);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(kChildId2, kRouteId2, true, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
// 1 visible and 1 hidden loaded, 1 visible and 1 hidden loading
scheduler_.OnLoadingStateChanged(
TEST_F(ResourceSchedulerTest, LastCoalescedClientDeletionStopsTimer) {
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
true /* should_coalesce */);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
EXPECT_FALSE(mock_timer_->IsRunning());
scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
EXPECT_FALSE(mock_timer_->IsRunning());
EXPECT_FALSE(mock_timer_->IsRunning());
// To avoid errors on test tear down.
- scheduler_.OnClientCreated(kBackgroundChildId, kBackgroundRouteId, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId, kBackgroundRouteId, false, false);
}
TEST_F(ResourceSchedulerTest, LastCoalescedClientStartsLoadingStopsTimer) {
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
true /* should_coalesce */);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
EXPECT_FALSE(mock_timer_->IsRunning());
scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
EXPECT_FALSE(mock_timer_->IsRunning());
TEST_F(ResourceSchedulerTest, LastCoalescedClientBecomesVisibleStopsTimer) {
scheduler_.SetThrottleOptionsForTesting(true /* should_throttle */,
true /* should_coalesce */);
- scheduler_.OnClientCreated(kBackgroundChildId2, kBackgroundRouteId2, false);
+ scheduler_.OnClientCreated(
+ kBackgroundChildId2, kBackgroundRouteId2, false, false);
EXPECT_FALSE(mock_timer_->IsRunning());
scheduler_.OnLoadingStateChanged(kChildId, kRouteId, true);
EXPECT_FALSE(mock_timer_->IsRunning());
TEST_F(ResourceSchedulerTest, GetVisualSignalFromRenderViewHost) {
scoped_ptr<MockRenderProcessHostFactory> render_process_host_factory;
+ scoped_ptr<TestRenderViewHostFactory> render_view_host_factory;
scoped_ptr<TestBrowserContext> browser_context;
scoped_ptr<TestWebContents> web_contents_1;
scoped_ptr<TestWebContents> web_contents_2;
-
render_process_host_factory.reset(new MockRenderProcessHostFactory());
+ render_view_host_factory.reset(
+ new TestRenderViewHostFactory(render_process_host_factory.get()));
+
browser_context.reset(new TestBrowserContext());
scoped_refptr<SiteInstance> site_instance_1 =
SiteInstance::Create(browser_context.get());