cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ios / chrome / browser / snapshots / snapshots_util_unittest.mm
blob0b69f43558cbd8f2cb313582f7a56c9891d78a98
1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import "ios/chrome/browser/snapshots/snapshots_util.h"
7 #import <Foundation/Foundation.h>
8 #import <UIKit/UIKit.h>
10 #include "base/ios/ios_util.h"
11 #include "base/mac/foundation_util.h"
12 #include "base/path_service.h"
13 #include "base/strings/sys_string_conversions.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace {
18 bool RegexMatchesOneSnapshotPath(NSString* regexString) {
19   NSRegularExpression* regex =
20       [NSRegularExpression regularExpressionWithPattern:regexString
21                                                 options:0
22                                                   error:nullptr];
23   std::vector<base::FilePath> snapshotsPaths;
24   GetSnapshotsPaths(&snapshotsPaths);
25   int numberOfMatches = 0;
26   for (const base::FilePath& path : snapshotsPaths) {
27     NSString* string =
28         [NSString stringWithCString:path.value().c_str()
29                            encoding:[NSString defaultCStringEncoding]];
30     if ([regex numberOfMatchesInString:string
31                                options:0
32                                  range:NSMakeRange(0, [string length])])
33       numberOfMatches++;
34   }
35   return numberOfMatches == 1;
38 TEST(SnapshotsUtilTest, TestSnapshotList) {
39   NSString* scaleModifier = @"";
40   CGFloat scale = [UIScreen mainScreen].scale;
41   if (scale > 1) {
42     scaleModifier = [NSString stringWithFormat:@"@%.0fx", scale];
43   }
44   NSString* path = @"Main";
45   if (base::ios::IsRunningOnIOS8OrLater()) {
46     path = base::SysUTF8ToNSString(base::mac::BaseBundleID());
47   }
48   NSString* filename = @"UIApplicationAutomaticSnapshotDefault-LandscapeRight";
49   NSString* regex = [NSString
50       stringWithFormat:@".*/%@/%@%@.png$", path, filename, scaleModifier];
51   EXPECT_FALSE(RegexMatchesOneSnapshotPath(@".*"));
52   EXPECT_FALSE(RegexMatchesOneSnapshotPath(@"foo"));
53   EXPECT_TRUE(RegexMatchesOneSnapshotPath(@".*LandscapeRight.*"));
54   EXPECT_TRUE(RegexMatchesOneSnapshotPath(regex));
57 }  // anonymous namespace