|
| 1 | +// Copyright © 2017 The CefSharp Authors. All rights reserved. |
| 2 | +// |
| 3 | +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +using System.Threading.Tasks; |
| 6 | +using CefSharp.DevTools.Browser; |
| 7 | +using CefSharp.OffScreen; |
| 8 | +using Xunit; |
| 9 | +using Xunit.Abstractions; |
| 10 | + |
| 11 | +namespace CefSharp.Test.DevTools |
| 12 | +{ |
| 13 | + //NOTE: All Test classes must be part of this collection as it manages the Cef Initialize/Shutdown lifecycle |
| 14 | + [Collection(CefSharpFixtureCollection.Key)] |
| 15 | + public class DevToolsClientFacts |
| 16 | + { |
| 17 | + private readonly ITestOutputHelper output; |
| 18 | + private readonly CefSharpFixture fixture; |
| 19 | + |
| 20 | + public DevToolsClientFacts(ITestOutputHelper output, CefSharpFixture fixture) |
| 21 | + { |
| 22 | + this.fixture = fixture; |
| 23 | + this.output = output; |
| 24 | + } |
| 25 | + |
| 26 | + [Fact] |
| 27 | + public void CanConvertDevToolsObjectToDictionary() |
| 28 | + { |
| 29 | + var bounds = new Bounds |
| 30 | + { |
| 31 | + Height = 1, |
| 32 | + Width = 1, |
| 33 | + Left = 1, |
| 34 | + Top = 1, |
| 35 | + WindowState = WindowState.Fullscreen |
| 36 | + }; |
| 37 | + |
| 38 | + var dict = bounds.ToDictionary(); |
| 39 | + |
| 40 | + Assert.Equal(bounds.Height, (int)dict["height"]); |
| 41 | + Assert.Equal(bounds.Width, (int)dict["width"]); |
| 42 | + Assert.Equal(bounds.Top, (int)dict["top"]); |
| 43 | + Assert.Equal(bounds.Left, (int)dict["left"]); |
| 44 | + Assert.Equal("fullscreen", (string)dict["windowState"]); |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + [Fact] |
| 49 | + public async Task CanGetDevToolsProtocolVersion() |
| 50 | + { |
| 51 | + using (var browser = new ChromiumWebBrowser("www.google.com")) |
| 52 | + { |
| 53 | + await browser.LoadPageAsync(); |
| 54 | + |
| 55 | + using (var devToolsClient = browser.GetDevToolsClient()) |
| 56 | + { |
| 57 | + var response = await devToolsClient.Browser.GetVersionAsync(); |
| 58 | + var jsVersion = response.JsVersion; |
| 59 | + var revision = response.Revision; |
| 60 | + |
| 61 | + Assert.NotNull(jsVersion); |
| 62 | + Assert.NotNull(revision); |
| 63 | + |
| 64 | + output.WriteLine("DevTools Revision {0}", revision); |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + [Fact] |
| 70 | + public async Task CanGetDevToolsProtocolGetWindowForTarget() |
| 71 | + { |
| 72 | + using (var browser = new ChromiumWebBrowser("www.google.com")) |
| 73 | + { |
| 74 | + await browser.LoadPageAsync(); |
| 75 | + |
| 76 | + using (var devToolsClient = browser.GetDevToolsClient()) |
| 77 | + { |
| 78 | + var response = await devToolsClient.Browser.GetWindowForTargetAsync(); |
| 79 | + var windowId = response.WindowId; |
| 80 | + var bounds = response.Bounds; |
| 81 | + |
| 82 | + Assert.NotEqual(0, windowId); |
| 83 | + Assert.NotNull(bounds); |
| 84 | + Assert.True(bounds.Height > 0); |
| 85 | + Assert.True(bounds.Width > 0); |
| 86 | + Assert.True(bounds.WindowState.HasValue); |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + } |
| 92 | +} |
0 commit comments