Chromium Code Reviews| Index: chrome/browser/net/errorpage_test_util.cc |
| diff --git a/chrome/browser/net/errorpage_test_util.cc b/chrome/browser/net/errorpage_test_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f745821f4387545e89e34881e548a387d513efe8 |
| --- /dev/null |
| +++ b/chrome/browser/net/errorpage_test_util.cc |
| @@ -0,0 +1,38 @@ |
| +// Copyright (c) 2017 The Chromium Authors. All rights reserved. |
|
mmenke
2017/06/05 18:31:34
--(c)
satorux1
2017/06/06 08:52:37
done - but this file is gone.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/net/errorpage_test_util.h" |
| + |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/test/browser_test_utils.h" |
| +#include "net/base/net_errors.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace errorpage_test_util { |
| + |
| +bool IsDisplayingText(Browser* browser, const std::string& text) { |
| + // clang-format off |
| + std::string command = base::StringPrintf(R"( |
| + function isNodeVisible(node) { |
| + if (!node || node.classList.contains('hidden')) |
| + return false; |
| + if (!node.parentElement) |
| + return true; |
| + // Otherwise, we must check all parent nodes |
| + return isNodeVisible(node.parentElement); |
| + } |
| + var node = document.evaluate("//*[contains(text(),'%s')]", document, |
| + null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; |
| + domAutomationController.send(isNodeVisible(node)); |
| + )", text.c_str()); |
| + // clang-format on |
| + bool result = false; |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| + browser->tab_strip_model()->GetActiveWebContents(), command, &result)); |
| + return result; |
| +} |
| + |
| +} // namespace errorpage_test_util |