summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/network_message_observer_unittest.cc
diff options
context:
space:
mode:
authorchocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-09 19:48:05 +0000
committerchocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-09 19:48:05 +0000
commit8b3d17ed03c13b1be6de114485e9aa85d8f1eab1 (patch)
treeb5d9c816fcc1a3d35269865b5c9ce16a89a3d35b /chrome/browser/chromeos/network_message_observer_unittest.cc
parentc0a837462e1d989282060921db63068913b39ae4 (diff)
downloadchromium_src-8b3d17ed03c13b1be6de114485e9aa85d8f1eab1.zip
chromium_src-8b3d17ed03c13b1be6de114485e9aa85d8f1eab1.tar.gz
chromium_src-8b3d17ed03c13b1be6de114485e9aa85d8f1eab1.tar.bz2
Only show notification for low 3g data for the last data-based plan.
BUG=chromium-os:10010 TEST=manual Review URL: http://codereview.chromium.org/6347044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74319 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/network_message_observer_unittest.cc')
-rw-r--r--chrome/browser/chromeos/network_message_observer_unittest.cc80
1 files changed, 80 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/network_message_observer_unittest.cc b/chrome/browser/chromeos/network_message_observer_unittest.cc
new file mode 100644
index 0000000..a742696
--- /dev/null
+++ b/chrome/browser/chromeos/network_message_observer_unittest.cc
@@ -0,0 +1,80 @@
+// Copyright (c) 2010 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 "chrome/browser/chromeos/network_message_observer.h"
+
+#include "base/time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+
+namespace {
+
+CellularDataPlan CreateDataPlan(CellularDataPlanType type, int64 start_sec,
+ int64 end_sec, int64 bytes, int64 used) {
+ CellularDataPlan plan;
+ plan.plan_type = type;
+ plan.plan_start_time = base::Time::FromDoubleT(start_sec);
+ plan.plan_end_time = base::Time::FromDoubleT(end_sec);
+ plan.plan_data_bytes = bytes;
+ plan.data_bytes_used = used;
+ return plan;
+}
+
+} // namespace
+
+// Test the code that checks if a data plan is an applicable backup plan.
+TEST(NetworkMessageObserverTest, TestIsApplicableBackupPlan) {
+ // IsApplicableBackupPlan returns true if:
+ // (unlimited OR used bytes < max bytes) AND
+ // ((start time - 1 sec) <= end time of currently active plan).
+
+ // Current plan that ends at 100.
+ CellularDataPlan plan =
+ CreateDataPlan(CELLULAR_DATA_PLAN_UNLIMITED, 0, 100, 0, 0);
+
+ // Test unlimited plans.
+ CellularDataPlan time_50 =
+ CreateDataPlan(CELLULAR_DATA_PLAN_UNLIMITED, 50, 500, 0, 0);
+ CellularDataPlan time_100 =
+ CreateDataPlan(CELLULAR_DATA_PLAN_UNLIMITED, 100, 500, 0, 0);
+ CellularDataPlan time_101 =
+ CreateDataPlan(CELLULAR_DATA_PLAN_UNLIMITED, 101, 500, 0, 0);
+ CellularDataPlan time_102 =
+ CreateDataPlan(CELLULAR_DATA_PLAN_UNLIMITED, 102, 500, 0, 0);
+ EXPECT_TRUE(NetworkMessageObserver::IsApplicableBackupPlan(&plan, &time_50));
+ EXPECT_TRUE(NetworkMessageObserver::IsApplicableBackupPlan(&plan, &time_100));
+ EXPECT_TRUE(NetworkMessageObserver::IsApplicableBackupPlan(&plan, &time_101));
+ EXPECT_FALSE(NetworkMessageObserver::IsApplicableBackupPlan(&plan,
+ &time_102));
+
+ // Test data plans.
+ CellularDataPlan data_0_0 =
+ CreateDataPlan(CELLULAR_DATA_PLAN_METERED_PAID, 100, 500, 0, 0);
+ CellularDataPlan data_100_0 =
+ CreateDataPlan(CELLULAR_DATA_PLAN_METERED_PAID, 100, 500, 100, 0);
+ CellularDataPlan data_100_50 =
+ CreateDataPlan(CELLULAR_DATA_PLAN_METERED_PAID, 100, 500, 100, 50);
+ CellularDataPlan data_100_100 =
+ CreateDataPlan(CELLULAR_DATA_PLAN_METERED_PAID, 100, 500, 100, 100);
+ CellularDataPlan data_100_200 =
+ CreateDataPlan(CELLULAR_DATA_PLAN_METERED_PAID, 100, 500, 100, 200);
+ CellularDataPlan data_100_0_gap =
+ CreateDataPlan(CELLULAR_DATA_PLAN_METERED_PAID, 200, 500, 100, 0);
+ EXPECT_FALSE(NetworkMessageObserver::IsApplicableBackupPlan(&plan,
+ &data_0_0));
+ EXPECT_TRUE(NetworkMessageObserver::IsApplicableBackupPlan(&plan,
+ &data_100_0));
+ EXPECT_TRUE(NetworkMessageObserver::IsApplicableBackupPlan(&plan,
+ &data_100_50));
+ EXPECT_FALSE(NetworkMessageObserver::IsApplicableBackupPlan(&plan,
+ &data_100_100));
+ EXPECT_FALSE(NetworkMessageObserver::IsApplicableBackupPlan(&plan,
+ &data_100_200));
+ EXPECT_FALSE(NetworkMessageObserver::IsApplicableBackupPlan(&plan,
+ &data_100_0_gap));
+}
+
+
+} // namespace chromeos