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

Side by Side Diff: chrome/test/chromedriver/util_unittest.cc

Issue 1669453002: [chromedriver] Apply page load timeout to slow cross-process navigations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "chrome/test/chromedriver/chrome/status.h" 11 #include "chrome/test/chromedriver/chrome/status.h"
12 #include "chrome/test/chromedriver/util.h" 12 #include "chrome/test/chromedriver/util.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 using base::TimeDelta;
16
15 TEST(UnzipSoleFile, Entry) { 17 TEST(UnzipSoleFile, Entry) {
16 base::ScopedTempDir temp_dir; 18 base::ScopedTempDir temp_dir;
17 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 19 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
18 std::string data; 20 std::string data;
19 // A zip entry sent from a Java WebDriver client (v2.20) that contains a 21 // A zip entry sent from a Java WebDriver client (v2.20) that contains a
20 // file with the contents "COW\n". 22 // file with the contents "COW\n".
21 const char kBase64ZipEntry[] = 23 const char kBase64ZipEntry[] =
22 "UEsDBBQACAAIAJpyXEAAAAAAAAAAAAAAAAAEAAAAdGVzdHP2D+" 24 "UEsDBBQACAAIAJpyXEAAAAAAAAAAAAAAAAAEAAAAdGVzdHP2D+"
23 "cCAFBLBwi/wAzGBgAAAAQAAAA="; 25 "cCAFBLBwi/wAzGBgAAAAQAAAA=";
24 ASSERT_TRUE(base::Base64Decode(kBase64ZipEntry, &data)); 26 ASSERT_TRUE(base::Base64Decode(kBase64ZipEntry, &data));
(...skipping 16 matching lines...) Expand all
41 "wAzGBAAAAAQAAAADAAAAAAAAAAAAAACggQAAAABtb29QSwUGAAAAAAEAAQAxAAAAJQAAAAA" 43 "wAzGBAAAAAQAAAADAAAAAAAAAAAAAACggQAAAABtb29QSwUGAAAAAAEAAQAxAAAAJQAAAAA"
42 "A"; 44 "A";
43 ASSERT_TRUE(base::Base64Decode(kBase64ZipArchive, &data)); 45 ASSERT_TRUE(base::Base64Decode(kBase64ZipArchive, &data));
44 base::FilePath file; 46 base::FilePath file;
45 Status status = UnzipSoleFile(temp_dir.path(), data, &file); 47 Status status = UnzipSoleFile(temp_dir.path(), data, &file);
46 ASSERT_EQ(kOk, status.code()) << status.message(); 48 ASSERT_EQ(kOk, status.code()) << status.message();
47 std::string contents; 49 std::string contents;
48 ASSERT_TRUE(base::ReadFileToString(file, &contents)); 50 ASSERT_TRUE(base::ReadFileToString(file, &contents));
49 ASSERT_STREQ("COW\n", contents.c_str()); 51 ASSERT_STREQ("COW\n", contents.c_str());
50 } 52 }
53
54 TEST(TimeoutTest, Basics) {
55 Timeout timeout;
56 EXPECT_FALSE(timeout.is_set());
57 EXPECT_FALSE(timeout.IsExpired());
58 EXPECT_EQ(TimeDelta::Max(), timeout.GetDuration());
59 EXPECT_EQ(TimeDelta::Max(), timeout.GetRemainingTime());
60
61 timeout.SetDuration(TimeDelta());
62 EXPECT_TRUE(timeout.is_set());
63 EXPECT_TRUE(timeout.IsExpired());
64 EXPECT_EQ(TimeDelta(), timeout.GetDuration());
65 EXPECT_GE(TimeDelta(), timeout.GetRemainingTime());
66 }
67
68 TEST(TimeoutTest, Derive) {
69 Timeout timeout(TimeDelta::FromMinutes(5));
70 EXPECT_TRUE(timeout.is_set());
71 EXPECT_FALSE(timeout.IsExpired());
72 EXPECT_EQ(TimeDelta::FromMinutes(5), timeout.GetDuration());
73 EXPECT_GE(TimeDelta::FromMinutes(5), timeout.GetRemainingTime());
74
75 Timeout small = Timeout(TimeDelta::FromSeconds(10), &timeout);
76 EXPECT_TRUE(small.is_set());
77 EXPECT_FALSE(small.IsExpired());
78 EXPECT_EQ(TimeDelta::FromSeconds(10), small.GetDuration());
79
80 Timeout large = Timeout(TimeDelta::FromMinutes(30), &timeout);
81 EXPECT_TRUE(large.is_set());
82 EXPECT_FALSE(large.IsExpired());
83 EXPECT_GE(timeout.GetDuration(), large.GetDuration());
84 }
85
86 TEST(TimeoutTest, DeriveExpired) {
87 Timeout timeout((TimeDelta()));
88 EXPECT_TRUE(timeout.is_set());
89 EXPECT_TRUE(timeout.IsExpired());
90
91 Timeout derived = Timeout(TimeDelta::FromSeconds(10), &timeout);
92 EXPECT_TRUE(derived.is_set());
93 EXPECT_TRUE(derived.IsExpired());
94 EXPECT_GE(TimeDelta(), derived.GetDuration());
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698