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

Unified Diff: components/offline_pages/request_header/offline_page_header_unittest.cc

Issue 2337363002: Load live version when reloading an offline page on connected network (Closed)
Patch Set: Update BUILD.gn Created 4 years, 3 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
« no previous file with comments | « components/offline_pages/request_header/offline_page_header.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/offline_pages/request_header/offline_page_header_unittest.cc
diff --git a/components/offline_pages/request_header/offline_page_header_unittest.cc b/components/offline_pages/request_header/offline_page_header_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..744a66f66f5a6d0a3a30ba68bfb64fe55c3821d0
--- /dev/null
+++ b/components/offline_pages/request_header/offline_page_header_unittest.cc
@@ -0,0 +1,82 @@
+// Copyright 2016 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 "components/offline_pages/request_header/offline_page_header.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace offline_pages {
+
+class OfflinePageHeaderTest : public testing::Test {
+ public:
+ OfflinePageHeaderTest() {}
+ ~OfflinePageHeaderTest() override {}
+
+ bool ParseFromHeaderValue(const std::string& header_value,
+ bool* need_to_persist,
+ OfflinePageHeader::Reason* reason,
+ std::string* id) {
+ OfflinePageHeader header(header_value);
+ *need_to_persist = header.need_to_persist;
+ *reason = header.reason;
+ *id = header.id;
+ return !header.did_fail_parsing_for_test;
+ }
+};
+
+TEST_F(OfflinePageHeaderTest, Parse) {
+ bool need_to_persist;
+ OfflinePageHeader::Reason reason;
+ std::string id;
+
+ EXPECT_FALSE(ParseFromHeaderValue("", &need_to_persist, &reason, &id));
+ EXPECT_FALSE(ParseFromHeaderValue(" ", &need_to_persist, &reason, &id));
+ EXPECT_FALSE(ParseFromHeaderValue(" , ", &need_to_persist, &reason, &id));
+ EXPECT_FALSE(ParseFromHeaderValue("reason", &need_to_persist, &reason, &id));
+ EXPECT_FALSE(ParseFromHeaderValue("a b c", &need_to_persist, &reason, &id));
+
+ EXPECT_FALSE(
+ ParseFromHeaderValue("persist=aa", &need_to_persist, &reason, &id));
+
+ EXPECT_TRUE(
+ ParseFromHeaderValue("persist=1", &need_to_persist, &reason, &id));
+ EXPECT_TRUE(need_to_persist);
+
+ EXPECT_TRUE(
+ ParseFromHeaderValue("persist=0", &need_to_persist, &reason, &id));
+ EXPECT_FALSE(need_to_persist);
+ EXPECT_EQ(OfflinePageHeader::Reason::NONE, reason);
+ EXPECT_EQ("", id);
+
+ EXPECT_FALSE(
+ ParseFromHeaderValue("reason=foo", &need_to_persist, &reason, &id));
+
+ EXPECT_TRUE(
+ ParseFromHeaderValue("reason=error", &need_to_persist, &reason, &id));
+ EXPECT_FALSE(need_to_persist);
+ EXPECT_EQ(OfflinePageHeader::Reason::NET_ERROR, reason);
+ EXPECT_EQ("", id);
+
+ EXPECT_TRUE(ParseFromHeaderValue("id=a1b2", &need_to_persist, &reason, &id));
+ EXPECT_FALSE(need_to_persist);
+ EXPECT_EQ(OfflinePageHeader::Reason::NONE, reason);
+ EXPECT_EQ("a1b2", id);
+
+ EXPECT_TRUE(ParseFromHeaderValue("persist=1 reason=download id=a1b2",
+ &need_to_persist, &reason, &id));
+ EXPECT_TRUE(need_to_persist);
+ EXPECT_EQ(OfflinePageHeader::Reason::DOWNLOAD, reason);
+ EXPECT_EQ("a1b2", id);
+}
+
+TEST_F(OfflinePageHeaderTest, ToString) {
+ OfflinePageHeader header;
+ header.need_to_persist = true;
+ header.reason = OfflinePageHeader::Reason::DOWNLOAD;
+ header.id = "a1b2";
+ EXPECT_EQ("X-Chrome-offline: persist=1 reason=download id=a1b2",
+ header.GetCompleteHeaderString());
+}
+
+} // namespace offline_pages
« no previous file with comments | « components/offline_pages/request_header/offline_page_header.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698