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

Unified Diff: ios/chrome/browser/metrics/size_class_recorder_unittest.mm

Issue 2585233003: Upstream Chrome on iOS source code [2/11]. (Closed)
Patch Set: Created 4 years 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
Index: ios/chrome/browser/metrics/size_class_recorder_unittest.mm
diff --git a/ios/chrome/browser/metrics/size_class_recorder_unittest.mm b/ios/chrome/browser/metrics/size_class_recorder_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..238e13a6b97d49a4a4df6a498a81538e041a5250
--- /dev/null
+++ b/ios/chrome/browser/metrics/size_class_recorder_unittest.mm
@@ -0,0 +1,206 @@
+// Copyright 2015 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.
+
+#import "ios/chrome/browser/metrics/size_class_recorder.h"
+#import "ios/chrome/browser/metrics/size_class_recorder_private.h"
+
+#include <memory>
+
+#import "base/mac/scoped_nsobject.h"
+#include "base/test/histogram_tester.h"
+#import "ios/chrome/browser/ui/ui_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+using ios_internal::SizeClassForReporting;
+using ios_internal::SizeClassForReportingForUIUserInterfaceSizeClass;
+
+namespace {
+
+const char kSizeClassUsedHistogramName[] = "Tab.HorizontalSizeClassUsed";
+
+const char kPageLoadSizeClassHistogramName[] =
+ "Tab.PageLoadInHorizontalSizeClass";
+
+class SizeClassRecorderTest : public PlatformTest {
+ protected:
+ void SetUp() override {
+ PlatformTest::SetUp();
+ histogram_tester_.reset(new base::HistogramTester());
+ }
+
+ base::scoped_nsobject<SizeClassRecorder> recorder_;
+ std::unique_ptr<base::HistogramTester> histogram_tester_;
+};
+
+TEST_F(SizeClassRecorderTest, Initialization_SizeClassUnspecified) {
+ // SizeClassRecoder is only available on iPad devices.
+ if (!IsIPadIdiom())
+ return;
+
+ recorder_.reset([[SizeClassRecorder alloc]
+ initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]);
+ recorder_.reset();
+
+ histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0);
+ histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
+}
+
+TEST_F(SizeClassRecorderTest, Initialization_SizeClassCompact) {
+ // SizeClassRecoder is only available on iPad devices.
+ if (!IsIPadIdiom())
+ return;
+
+ recorder_.reset([[SizeClassRecorder alloc]
+ initWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact]);
+ recorder_.reset();
+
+ histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0);
+ histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
+}
+
+TEST_F(SizeClassRecorderTest, Initialization_SizeClassRegular) {
+ // SizeClassRecoder is only available on iPad devices.
+ if (!IsIPadIdiom())
+ return;
+
+ recorder_.reset([[SizeClassRecorder alloc]
+ initWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular]);
+ recorder_.reset();
+
+ histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0);
+ histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
+}
+
+TEST_F(SizeClassRecorderTest, RecordInitialSizeClassOnAppBecomeActive) {
+ // SizeClassRecoder is only available on iPad devices.
+ if (!IsIPadIdiom())
+ return;
+
+ recorder_.reset([[SizeClassRecorder alloc]
+ initWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact]);
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:UIApplicationDidBecomeActiveNotification
+ object:nil];
+
+ histogram_tester_->ExpectUniqueSample(kSizeClassUsedHistogramName,
+ SizeClassForReporting::COMPACT, 1);
+ histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
+}
+
+TEST_F(SizeClassRecorderTest,
+ DontRecordInitialSizeClassSubsequentAppBecomeActive) {
+ // SizeClassRecoder is only available on iPad devices.
+ if (!IsIPadIdiom())
+ return;
+
+ recorder_.reset([[SizeClassRecorder alloc]
+ initWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact]);
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:UIApplicationDidBecomeActiveNotification
+ object:nil];
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:UIApplicationDidBecomeActiveNotification
+ object:nil];
+
+ histogram_tester_->ExpectUniqueSample(kSizeClassUsedHistogramName,
+ SizeClassForReporting::COMPACT, 1);
+ histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
+}
+
+TEST_F(SizeClassRecorderTest, RecordSizeClassChangeInForeground) {
+ // SizeClassRecoder is only available on iPad devices.
+ if (!IsIPadIdiom())
+ return;
+
+ recorder_.reset([[SizeClassRecorder alloc]
+ initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]);
+ [recorder_ horizontalSizeClassDidChange:UIUserInterfaceSizeClassRegular];
+
+ histogram_tester_->ExpectUniqueSample(kSizeClassUsedHistogramName,
+ SizeClassForReporting::REGULAR, 1);
+ histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
+}
+
+TEST_F(SizeClassRecorderTest, DontRecordSizeClassChangeInBackground) {
+ // SizeClassRecoder is only available on iPad devices.
+ if (!IsIPadIdiom())
+ return;
+
+ recorder_.reset([[SizeClassRecorder alloc]
+ initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]);
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:UIApplicationDidEnterBackgroundNotification
+ object:nil];
+ [recorder_ horizontalSizeClassDidChange:UIUserInterfaceSizeClassRegular];
+
+ histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0);
+ histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
+}
+
+TEST_F(SizeClassRecorderTest,
+ RecordSizeClassChangeInForegroundAfterBackground) {
+ // SizeClassRecoder is only available on iPad devices.
+ if (!IsIPadIdiom())
+ return;
+
+ recorder_.reset([[SizeClassRecorder alloc]
+ initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]);
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:UIApplicationDidEnterBackgroundNotification
+ object:nil];
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:UIApplicationWillEnterForegroundNotification
+ object:nil];
+ [recorder_ horizontalSizeClassDidChange:UIUserInterfaceSizeClassCompact];
+
+ histogram_tester_->ExpectUniqueSample(kSizeClassUsedHistogramName,
+ SizeClassForReporting::COMPACT, 1);
+ histogram_tester_->ExpectTotalCount(kPageLoadSizeClassHistogramName, 0);
+}
+
+TEST_F(SizeClassRecorderTest, RecordSizeClassOnPageLoaded_Unspecified) {
+ // SizeClassRecoder is only available on iPad devices.
+ if (!IsIPadIdiom())
+ return;
+
+ recorder_.reset([[SizeClassRecorder alloc]
+ initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]);
+ [recorder_
+ pageLoadedWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified];
+
+ histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0);
+ histogram_tester_->ExpectUniqueSample(kPageLoadSizeClassHistogramName,
+ SizeClassForReporting::UNSPECIFIED, 1);
+}
+
+TEST_F(SizeClassRecorderTest, RecordSizeClassOnPageLoaded_Compact) {
+ // SizeClassRecoder is only available on iPad devices.
+ if (!IsIPadIdiom())
+ return;
+
+ recorder_.reset([[SizeClassRecorder alloc]
+ initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]);
+ [recorder_ pageLoadedWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];
+
+ histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0);
+ histogram_tester_->ExpectUniqueSample(kPageLoadSizeClassHistogramName,
+ SizeClassForReporting::COMPACT, 1);
+}
+
+TEST_F(SizeClassRecorderTest, RecordSizeClassOnPageLoaded_Regular) {
+ // SizeClassRecoder is only available on iPad devices.
+ if (!IsIPadIdiom())
+ return;
+
+ recorder_.reset([[SizeClassRecorder alloc]
+ initWithHorizontalSizeClass:UIUserInterfaceSizeClassUnspecified]);
+ [recorder_ pageLoadedWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];
+
+ histogram_tester_->ExpectTotalCount(kSizeClassUsedHistogramName, 0);
+ histogram_tester_->ExpectUniqueSample(kPageLoadSizeClassHistogramName,
+ SizeClassForReporting::REGULAR, 1);
+}
+
+} // namespace
« no previous file with comments | « ios/chrome/browser/metrics/size_class_recorder_private.h ('k') | ios/chrome/browser/metrics/tab_usage_recorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698