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

Unified Diff: ios/web/ui_web_view_util_unittest.mm

Issue 1043243003: Upstream most of ios/web/net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove accidentally-added clients Created 5 years, 9 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 | « ios/web/ui_web_view_util.mm ('k') | ios/web/web_state/ui/crw_static_file_web_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/ui_web_view_util_unittest.mm
diff --git a/ios/web/ui_web_view_util_unittest.mm b/ios/web/ui_web_view_util_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..0354579d5c62b8c8f4f2611ccec4110768708d2f
--- /dev/null
+++ b/ios/web/ui_web_view_util_unittest.mm
@@ -0,0 +1,54 @@
+// Copyright 2014 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/web/ui_web_view_util.h"
+
+#import "ios/web/public/test/test_web_client.h"
+#include "testing/gtest_mac.h"
+#include "testing/platform_test.h"
+
+namespace {
+
+// Returns user agent string registered for UIWebView.
+NSString* GetUserAgent() {
+ return [[NSUserDefaults standardUserDefaults] stringForKey:@"UserAgent"];
+}
+
+class UIWebViewUtilTest : public PlatformTest {
+ protected:
+ void SetUp() override {
+ PlatformTest::SetUp();
+ test_web_client_.SetUserAgent("DesktopUA", true);
+ test_web_client_.SetUserAgent("RegularUA", false);
+ web::SetWebClient(&test_web_client_);
+ }
+ void TearDown() override {
+ web::SetWebClient(nullptr);
+ PlatformTest::TearDown();
+ }
+ private:
+ // WebClient that returns test user agent.
+ web::TestWebClient test_web_client_;
+};
+
+// Tests registration of a non-desktop user agent.
+TEST_F(UIWebViewUtilTest, BuildAndRegisterNonDesktopUserAgentForUIWebView) {
+ web::BuildAndRegisterUserAgentForUIWebView(@"1231546541321", NO);
+ EXPECT_NSEQ(@"RegularUA (1231546541321)", GetUserAgent());
+}
+
+// Tests registration of a desktop user agent.
+TEST_F(UIWebViewUtilTest, BuildAndRegisterDesktopUserAgentForUIWebView) {
+ web::BuildAndRegisterUserAgentForUIWebView(@"1231546541321", YES);
+ EXPECT_NSEQ(@"DesktopUA (1231546541321)", GetUserAgent());
+}
+
+// Tests web::RegisterUserAgentForUIWebView function that it correctly registers
+// arbitrary user agent.
+TEST_F(UIWebViewUtilTest, RegisterUserAgentForUIWebView) {
+ web::RegisterUserAgentForUIWebView(@"UA");
+ EXPECT_NSEQ(@"UA", GetUserAgent());
+}
+
+} // namespace
« no previous file with comments | « ios/web/ui_web_view_util.mm ('k') | ios/web/web_state/ui/crw_static_file_web_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698