summaryrefslogtreecommitdiffstats
path: root/ios/net/nsurlrequest_util_unittest.mm
blob: 01bd2f74646a73fd66e157e248cdb5fd92d60aca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// 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.

#include "ios/net/nsurlrequest_util.h"

#include "base/mac/scoped_nsobject.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {

// Tests that FormatUrlRequestForLogging outputs the string in the form:
// request:<url> request.mainDocURL:<mainDocumentURL>.
TEST(NSURLRequestUtilTest, FormatUrlRequestForLogging) {
  base::scoped_nsobject<NSMutableURLRequest> request(
      [[NSMutableURLRequest alloc] init]);
  request.get().URL = [NSURL URLWithString:@"http://www.google.com"];
  request.get().mainDocumentURL =
      [NSURL URLWithString:@"http://www.google1.com"];
  std::string actualString, expectedString;

  actualString = net::FormatUrlRequestForLogging(request);
  expectedString = "request: http://www.google.com"
                   " request.mainDocURL: http://www.google1.com";
  EXPECT_EQ(expectedString, actualString);

  request.get().URL = nil;
  request.get().mainDocumentURL =
      [NSURL URLWithString:@"http://www.google1.com"];
  actualString = net::FormatUrlRequestForLogging(request);
  expectedString = "request: [nil] request.mainDocURL: http://www.google1.com";
  EXPECT_EQ(expectedString, actualString);

  request.get().URL = [NSURL URLWithString:@"http://www.google.com"];
  request.get().mainDocumentURL = nil;
  actualString = net::FormatUrlRequestForLogging(request);
  expectedString = "request: http://www.google.com request.mainDocURL: [nil]";
  EXPECT_EQ(expectedString, actualString);

  request.get().URL = nil;
  request.get().mainDocumentURL = nil;
  actualString = net::FormatUrlRequestForLogging(request);
  expectedString = "request: [nil] request.mainDocURL: [nil]";
  EXPECT_EQ(expectedString, actualString);
}

}  // namespace