diff options
author | droger <droger@chromium.org> | 2015-02-17 08:41:23 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-17 16:42:16 +0000 |
commit | 17f3dfc806ea91dd71f3ba7d4b172a191caa2351 (patch) | |
tree | 48c68109dc3f2f0e531fdc67ea1170d64c0855f3 /ios/chrome/browser/snapshots/snapshots_util_unittest.mm | |
parent | b4e89950984d01c670fde7d062e1ff4ec7ef9d97 (diff) | |
download | chromium_src-17f3dfc806ea91dd71f3ba7d4b172a191caa2351.zip chromium_src-17f3dfc806ea91dd71f3ba7d4b172a191caa2351.tar.gz chromium_src-17f3dfc806ea91dd71f3ba7d4b172a191caa2351.tar.bz2 |
Upstream //ios/chrome/browser/snapshots
snapshots_util is also moved from ui/ to snapshots/ as part of this CL.
NOPRESUBMIT=true
Review URL: https://codereview.chromium.org/862693003
Cr-Commit-Position: refs/heads/master@{#316584}
Diffstat (limited to 'ios/chrome/browser/snapshots/snapshots_util_unittest.mm')
-rw-r--r-- | ios/chrome/browser/snapshots/snapshots_util_unittest.mm | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/ios/chrome/browser/snapshots/snapshots_util_unittest.mm b/ios/chrome/browser/snapshots/snapshots_util_unittest.mm new file mode 100644 index 0000000..81e395b --- /dev/null +++ b/ios/chrome/browser/snapshots/snapshots_util_unittest.mm @@ -0,0 +1,57 @@ +// Copyright 2011 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/snapshots/snapshots_util.h" + +#import <Foundation/Foundation.h> +#import <UIKit/UIKit.h> + +#include "base/ios/ios_util.h" +#include "base/mac/foundation_util.h" +#include "base/path_service.h" +#include "base/strings/sys_string_conversions.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +bool RegexMatchesOneSnapshotPath(NSString* regexString) { + NSRegularExpression* regex = + [NSRegularExpression regularExpressionWithPattern:regexString + options:0 + error:NULL]; + std::vector<base::FilePath> snapshotsPaths; + GetSnapshotsPaths(&snapshotsPaths); + int numberOfMatches = 0; + for (const base::FilePath& path : snapshotsPaths) { + NSString* string = + [NSString stringWithCString:path.value().c_str() + encoding:[NSString defaultCStringEncoding]]; + if ([regex numberOfMatchesInString:string + options:0 + range:NSMakeRange(0, [string length])]) + numberOfMatches++; + } + return numberOfMatches == 1; +} + +TEST(SnapshotsUtilTest, TestSnapshotList) { + NSString* scaleModifier = @""; + CGFloat scale = [UIScreen mainScreen].scale; + if (scale > 1) { + scaleModifier = [NSString stringWithFormat:@"@%.0fx", scale]; + } + NSString* path = @"Main"; + if (base::ios::IsRunningOnIOS8OrLater()) { + path = base::SysUTF8ToNSString(base::mac::BaseBundleID()); + } + NSString* filename = @"UIApplicationAutomaticSnapshotDefault-LandscapeRight"; + NSString* regex = [NSString + stringWithFormat:@".*/%@/%@%@.png$", path, filename, scaleModifier]; + EXPECT_FALSE(RegexMatchesOneSnapshotPath(@".*")); + EXPECT_FALSE(RegexMatchesOneSnapshotPath(@"foo")); + EXPECT_TRUE(RegexMatchesOneSnapshotPath(@".*LandscapeRight.*")); + EXPECT_TRUE(RegexMatchesOneSnapshotPath(regex)); +} + +} // anonymous namespace |