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

Unified Diff: src/data_plan_unittest.cc

Issue 4114002: cashew: data plans: used bytes should be optional for unlimited plans (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git
Patch Set: jglasgow review fixes Created 10 years, 2 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 | « src/data_plan.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/data_plan_unittest.cc
diff --git a/src/data_plan_unittest.cc b/src/data_plan_unittest.cc
index b5f04dbbeae94674967a43a41514ce5340aa6949..fe4e15d05abdf4781258f20348770c6957b60254 100644
--- a/src/data_plan_unittest.cc
+++ b/src/data_plan_unittest.cc
@@ -2,23 +2,87 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <base/json/json_reader.h>
+#include <base/scoped_ptr.h>
#include <gtest/gtest.h>
#include "src/data_plan.h"
+#include "src/policy.h"
namespace cashew {
// test fixture for DataPlan unit tests
class DataPlanTest: public ::testing::Test {
protected:
- DataPlanTest() {}
- virtual ~DataPlanTest() {}
- virtual void SetUp() {}
- virtual void TearDown() {}
+ DataPlanTest() : policy_(NULL) {}
+
+ virtual ~DataPlanTest() {
+ EXPECT_TRUE(policy_ == NULL);
+ }
+
+ virtual void SetUp() {
+ EXPECT_TRUE(policy_ == NULL);
+ policy_ = Policy::GetPolicy(kTestCarrierName);
+ ASSERT_TRUE(policy_ != NULL);
+ }
+
+ virtual void TearDown() {
+ delete policy_;
+ policy_ = NULL;
+ }
+
+ // hardcoded JSON data plan representations
+ static const char *kMeteredWithUsedBytesJSON;
+ static const char *kMeteredWithNoUsedBytesJSON;
+ static const char *kUnlimitedWithUsedBytesJSON;
+ static const char *kUnlimitedWithNoUsedBytesJSON;
+
+ // test carrier for constructing policy
+ static const char *kTestCarrierName;
+
+ Policy *policy_;
};
typedef DataPlanTest DataPlanDeathTest;
+const char *DataPlanTest::kMeteredWithUsedBytesJSON =
+ "{\"lastUpdate\" : \"2010-09-20T12:01:00Z\","
+ "\"planName\" : \"Super-Awesome Chromium OS Plan\","
+ "\"planType\" : \"METERED_PAID\","
+ "\"maxBytes\" : 104857600,"
+ "\"usedBytes\" : 52428800,"
+ "\"expirationTime\" : \"2010-09-30T23:59:59\","
+ "\"startTime\" : \"2010-09-01T00:00:00\""
+ "}";
+
+const char *DataPlanTest::kMeteredWithNoUsedBytesJSON =
+ "{\"lastUpdate\" : \"2010-09-20T12:01:00Z\","
+ "\"planName\" : \"Super-Awesome Chromium OS Plan\","
+ "\"planType\" : \"METERED_PAID\","
+ "\"maxBytes\" : 104857600,"
+ "\"expirationTime\" : \"2010-09-30T23:59:59\","
+ "\"startTime\" : \"2010-09-01T00:00:00\""
+ "}";
+
+const char *DataPlanTest::kUnlimitedWithUsedBytesJSON =
+ "{\"lastUpdate\" : \"2010-09-20T12:01:00Z\","
+ "\"planName\" : \"All-You-Can-Eat Day Pass\","
+ "\"planType\" : \"UNLIMITED\","
+ "\"usedBytes\" : 52428800,"
+ "\"expirationTime\" : \"2010-09-20T23:59:59\","
+ "\"startTime\" : \"2010-09-20T00:00:00\""
+ "}";
+
+const char *DataPlanTest::kUnlimitedWithNoUsedBytesJSON =
+ "{\"lastUpdate\" : \"2010-09-20T12:01:00Z\","
+ "\"planName\" : \"All-You-Can-Eat Day Pass\","
+ "\"planType\" : \"UNLIMITED\","
+ "\"expirationTime\" : \"2010-09-20T23:59:59\","
+ "\"startTime\" : \"2010-09-20T00:00:00\""
+ "}";
+
+const char *DataPlanTest::kTestCarrierName = "Test Carrier";
+
TEST_F(DataPlanTest, UtcTimeString) {
static const char *kTimeStringToTest = "2010-09-20T23:59:59Z";
base::Time time;
@@ -81,4 +145,60 @@ TEST_F(DataPlanDeathTest, NullTimeOutPtr) {
"Check failed: 'time_out' Must be non NULL");
}
+TEST_F(DataPlanTest, FromDictionaryValueMeteredWithUsedBytes) {
+ scoped_ptr<Value> value(base::JSONReader::Read(kMeteredWithUsedBytesJSON,
+ true));
+ ASSERT_TRUE(value != NULL);
+ ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY));
+ const DictionaryValue *dict_value =
+ static_cast<const DictionaryValue*>(value.get());
+ DataPlan *plan = DataPlan::FromDictionaryValue(dict_value, policy_);
+ // we expect the call to have succeeeded, with the new data plan's used bytes
+ // property set to the value that was present in the JSON representation
+ ASSERT_TRUE(plan != NULL);
+ EXPECT_EQ(52428800, plan->GetDataBytesUsed());
+}
+
+TEST_F(DataPlanTest, FromDictonaryValueMeteredWithNoUsedBytes) {
+ scoped_ptr<Value> value(base::JSONReader::Read(kMeteredWithNoUsedBytesJSON,
+ true));
+ ASSERT_TRUE(value != NULL);
+ ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY));
+ const DictionaryValue *dict_value =
+ static_cast<const DictionaryValue*>(value.get());
+ DataPlan *plan = DataPlan::FromDictionaryValue(dict_value, policy_);
+ // the JSON representation for metered plans must include used bytes, so we
+ // expect the call to have failed
+ EXPECT_TRUE(plan == NULL);
+}
+
+TEST_F(DataPlanTest, FromDictionaryValueUnlimitedWithUsedBytes) {
+ scoped_ptr<Value> value(base::JSONReader::Read(kUnlimitedWithUsedBytesJSON,
+ true));
+ ASSERT_TRUE(value != NULL);
+ ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY));
+ const DictionaryValue *dict_value =
+ static_cast<const DictionaryValue*>(value.get());
+ DataPlan *plan = DataPlan::FromDictionaryValue(dict_value, policy_);
+ // we expect the call to have succeeeded, with the new data plan's used bytes
+ // property set to the value that was present in the JSON representation
+ ASSERT_TRUE(plan != NULL);
+ EXPECT_EQ(52428800, plan->GetDataBytesUsed());
+}
+
+TEST_F(DataPlanTest, FromDictionaryValueUnlimitedWithNoUsedBytes) {
+ scoped_ptr<Value> value(base::JSONReader::Read(kUnlimitedWithNoUsedBytesJSON,
+ true));
+ ASSERT_TRUE(value != NULL);
+ ASSERT_TRUE(value->IsType(Value::TYPE_DICTIONARY));
+ const DictionaryValue *dict_value =
+ static_cast<const DictionaryValue*>(value.get());
+ DataPlan *plan = DataPlan::FromDictionaryValue(dict_value, policy_);
+ // it's optional for the JSON representation for unlimited plans to include
+ // used bytes, so we expect the call to have succeeded. The new data plan's
+ // used bytes property should have been set to the default of 0.
+ ASSERT_TRUE(plan != NULL);
+ EXPECT_EQ(0, plan->GetDataBytesUsed());
+}
+
} // namespace cashew
« no previous file with comments | « src/data_plan.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698