summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32033.cs
blob: 2576525a49688a9b03b320f1d69ba5d5287da699 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 32033, "WebView on Windows does not display local HTML files", PlatformAffected.WinRT)]
	public class Bugzilla32033 : TestNavigationPage 
	{
		protected override void Init ()
		{
			PushAsync(Menu());
		}

		ContentPage Menu()
		{
			var page = new ContentPage();

			var layout = new StackLayout();

			var buttonLocal = new Button() {Text = "Local HTML file"};
			buttonLocal.Clicked += (sender, args) => Navigation.PushAsync(LocalUrl());
			
			var buttonHtmlString = new Button() {Text = "HTML string with links/refs to local files"};
			buttonHtmlString.Clicked += (sender, args) => Navigation.PushAsync(HtmlString());

			var buttonHtmlStringNoHead = new Button() {Text = "HTML string with links/refs to local files (no <head>)"};
			buttonHtmlStringNoHead.Clicked += (sender, args) => Navigation.PushAsync(HtmlStringNoHead());

			layout.Children.Add(buttonLocal);
			layout.Children.Add(buttonHtmlString);
			layout.Children.Add(buttonHtmlStringNoHead);

			page.Content = layout;

			return page;
		}

		static ContentPage LocalUrl()
		{
			var page = new ContentPage();

			var instructions = new Label
			{
				Text = @"The WebView below should contain the heading 'Xamarin Forms' and text reading 'This is a local HTML page'. All text should be italicized."
			};

			var webView = new WebView
			{
				WidthRequest = 300,
				HeightRequest = 500,
				HorizontalOptions = LayoutOptions.Fill,
				VerticalOptions = LayoutOptions.Fill,
				Source = new UrlWebViewSource() { Url = "local.html" }
			};

			var layout = new StackLayout { Children = { instructions, webView } };
			page.Content = layout;

			return page;
		}

		static ContentPage HtmlString()
		{
			var page = new ContentPage();

			var instructions = new Label
			{
				Text =
@"The WebView below should contain the heading 'Xamarin Forms', display the Xamarin logo, and have a link labeled 'next page'.
Clicking that link should navigate to a page with the heading 'Xamarin Forms' and text reading 'This is a local HTML page'. All text on both pages should be italicized."
			};

			var webView = new WebView
			{
				WidthRequest = 300,
				HeightRequest = 500,
				HorizontalOptions = LayoutOptions.Fill,
				VerticalOptions = LayoutOptions.Fill,
				Source = new HtmlWebViewSource
				{
					Html = @"<html>
<head>
<link rel=""stylesheet"" href=""default.css"">
</head>
<body>
<h1>Xamarin.Forms</h1>
<p>The CSS and image are loaded from local files!</p>
<img src='WebImages/XamarinLogo.png'/>
<p><a href=""local.html"">next page</a></p>
</body>
</html>"
				}
			};


			var layout = new StackLayout {HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill,  Children = { instructions, webView } };
			page.Content = layout;

			return page;
		}

		// This test verifies that the <base> injection solution works even if the HTML string doesn't explicitly include a <head> section
		static ContentPage HtmlStringNoHead()
		{
			var page = new ContentPage();

			var instructions = new Label
			{
				Text =
@"The WebView below should contain the heading 'Xamarin Forms', display the Xamarin logo, and have a link labeled 'next page'.
Clicking that link should navigate to a page with the heading 'Xamarin Forms' and text reading 'This is a local HTML page'. "
			};

			var webView = new WebView
			{
				WidthRequest = 300,
				HeightRequest = 500,
				HorizontalOptions = LayoutOptions.Fill,
				VerticalOptions = LayoutOptions.Fill,
				Source = new HtmlWebViewSource
				{
					Html = @"<html>
<body>
<h1>Xamarin.Forms</h1>
<p>The CSS and image are loaded from local files!</p>
<img src='WebImages/XamarinLogo.png'/>
<p><a href=""local.html"">next page</a></p>
</body>
</html>"
				}
			};


			var layout = new StackLayout {HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill,  Children = { instructions, webView } };
			page.Content = layout;

			return page;
		}
	}
}