This source file includes following definitions.
- SetUp
- TearDown
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "content/browser/loader/offline_policy.h"
#include "base/command_line.h"
#include "content/public/common/content_switches.h"
#include "net/base/load_flags.h"
#include "net/http/http_response_info.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/common/resource_type.h"
namespace content {
class OfflinePolicyTest : public testing::Test {
protected:
virtual void SetUp() {
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableOfflineCacheAccess);
policy_ = new OfflinePolicy;
}
virtual void TearDown() {
delete policy_;
policy_ = NULL;
}
OfflinePolicy* policy_;
};
TEST_F(OfflinePolicyTest, InitialState) {
EXPECT_EQ(net::LOAD_FROM_CACHE_IF_OFFLINE,
policy_->GetAdditionalLoadFlags(0, true));
EXPECT_EQ(net::LOAD_FROM_CACHE_IF_OFFLINE,
policy_->GetAdditionalLoadFlags(0, false));
}
TEST_F(OfflinePolicyTest, CompletedUncertain) {
EXPECT_EQ(net::LOAD_FROM_CACHE_IF_OFFLINE,
policy_->GetAdditionalLoadFlags(0, true));
net::HttpResponseInfo response_info;
policy_->UpdateStateForSuccessfullyStartedRequest(response_info);
EXPECT_EQ(net::LOAD_FROM_CACHE_IF_OFFLINE,
policy_->GetAdditionalLoadFlags(0, false));
}
TEST_F(OfflinePolicyTest, CompletedNoNetwork) {
EXPECT_EQ(net::LOAD_FROM_CACHE_IF_OFFLINE,
policy_->GetAdditionalLoadFlags(0, true));
net::HttpResponseInfo response_info;
response_info.server_data_unavailable = true;
policy_->UpdateStateForSuccessfullyStartedRequest(response_info);
EXPECT_EQ(net::LOAD_ONLY_FROM_CACHE,
policy_->GetAdditionalLoadFlags(0, false));
}
TEST_F(OfflinePolicyTest, CompletedNetwork) {
EXPECT_EQ(net::LOAD_FROM_CACHE_IF_OFFLINE,
policy_->GetAdditionalLoadFlags(0, true));
net::HttpResponseInfo response_info;
response_info.network_accessed = true;
policy_->UpdateStateForSuccessfullyStartedRequest(response_info);
EXPECT_EQ(0, policy_->GetAdditionalLoadFlags(0, false));
}
TEST_F(OfflinePolicyTest, NewNavigationReset) {
EXPECT_EQ(net::LOAD_FROM_CACHE_IF_OFFLINE,
policy_->GetAdditionalLoadFlags(0, true));
net::HttpResponseInfo response_info;
response_info.network_accessed = true;
policy_->UpdateStateForSuccessfullyStartedRequest(response_info);
EXPECT_EQ(0, policy_->GetAdditionalLoadFlags(0, false));
EXPECT_EQ(net::LOAD_FROM_CACHE_IF_OFFLINE,
policy_->GetAdditionalLoadFlags(0, true));
EXPECT_EQ(net::LOAD_FROM_CACHE_IF_OFFLINE,
policy_->GetAdditionalLoadFlags(0, false));
}
TEST_F(OfflinePolicyTest, ConsumerFlagOverride) {
EXPECT_EQ(0, policy_->GetAdditionalLoadFlags(net::LOAD_BYPASS_CACHE, true));
net::HttpResponseInfo response_info;
response_info.server_data_unavailable = true;
policy_->UpdateStateForSuccessfullyStartedRequest(response_info);
EXPECT_EQ(0, policy_->GetAdditionalLoadFlags(net::LOAD_BYPASS_CACHE, false));
}
}