// Copyright © 2017 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using System.Threading.Tasks;
using CefSharp.WinForms;
using Xunit;
using Xunit.Abstractions;

namespace CefSharp.Test.WinForms
{
    //NOTE: All Test classes must be part of this collection as it manages the Cef Initialize/Shutdown lifecycle
    [Collection(CefSharpFixtureCollection.Key)]
    public class WinFormsBrowserBasicFacts
    {
        private readonly ITestOutputHelper output;
        private readonly CefSharpFixture fixture;

        public WinFormsBrowserBasicFacts(ITestOutputHelper output, CefSharpFixture fixture)
        {
            this.fixture = fixture;
            this.output = output;
        }

        [WinFormsFact]
        public async Task CanLoadGoogle()
        {
            using (var browser = new ChromiumWebBrowser("www.google.com"))
            {
                var form = new System.Windows.Forms.Form();
                form.Controls.Add(browser);
                form.Show();

                await browser.LoadPageAsync();

                var mainFrame = browser.GetMainFrame();
                Assert.True(mainFrame.IsValid);
                Assert.True(mainFrame.Url.Contains("www.google"));

                output.WriteLine("Url {0}", mainFrame.Url);
            }
        }
    }
}

// Copyright © 2017 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using System.Threading.Tasks;
using CefSharp.WinForms;
using Xunit;
using Xunit.Abstractions;

namespace CefSharp.Test.WinForms
{
    //NOTE: All Test classes must be part of this collection as it manages the Cef Initialize/Shutdown lifecycle
    [Collection(CefSharpFixtureCollection.Key)]
    public class WinFormsBrowserBasicFacts
    {
        private readonly ITestOutputHelper output;
        private readonly CefSharpFixture fixture;

        public WinFormsBrowserBasicFacts(ITestOutputHelper output, CefSharpFixture fixture)
        {
            this.fixture = fixture;
            this.output = output;
        }

        [WinFormsFact]
        public async Task CanLoadGoogle()
        {
            using (var browser = new ChromiumWebBrowser("www.google.com"))
            {
                browser.Size = new System.Drawing.Size(1024, 768);
                browser.CreateControl();

                await browser.LoadPageAsync();

                var mainFrame = browser.GetMainFrame();
                Assert.True(mainFrame.IsValid);
                Assert.True(mainFrame.Url.Contains("www.google"));

                output.WriteLine("Url {0}", mainFrame.Url);
            }
        }
    }
}

Test - Avoid displaying Form in WinForms Test
Test - Avoid displaying Form in WinForms Test

Call CreateControl instead of displaying form.

Tooltips, context menus may not be positioned/displayed correctly as there is no parent form (window). For testing
purposes that's fine for now.
