Skip to content

Commit 4308012

Browse files
committed
More code to spec, starting to add tests
1 parent 9fde7cb commit 4308012

File tree

7 files changed

+78
-25
lines changed

7 files changed

+78
-25
lines changed

PushSharp.Google.Chrome/ChromePushChannel.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010

1111
using PushSharp.Core;
1212
using System.Net.Http;
13+
using System.Threading.Tasks;
1314

1415
namespace PushSharp.Google.Chrome
1516
{
1617
public class ChromePushChannel : IPushChannel
1718
{
1819
ChromePushChannelSettings chromeSettings = null;
1920

21+
public string AccessToken { get; private set; }
22+
public DateTime Expires { get; private set; }
23+
24+
2025
public ChromePushChannel(ChromePushChannelSettings channelSettings)
2126
{
2227
chromeSettings = channelSettings as ChromePushChannelSettings;
@@ -27,6 +32,27 @@ static ChromePushChannel()
2732
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, policyErrs) => { return true; };
2833
}
2934

35+
public void RefreshToken()
36+
{
37+
RefreshAccessToken ();
38+
}
39+
40+
public void RefreshAccessToken()
41+
{
42+
var http = new HttpClient ();
43+
44+
var p = new Dictionary<string, string> ();
45+
46+
p.Add ("client_id", chromeSettings.ClientId);
47+
p.Add ("client_secret", chromeSettings.ClientSecret);
48+
p.Add ("refresh_token", chromeSettings.RefreshToken);
49+
p.Add ("grant_type", chromeSettings.GrantType);
50+
51+
var response = http.PostAsync (chromeSettings.AuthUrl, new FormUrlEncodedContent (p)).Result;
52+
53+
Console.WriteLine ("RESPONSE: " + response.Content.ReadAsStringAsync().Result);
54+
}
55+
3056
public async void SendNotification(INotification notification, SendNotificationCallbackDelegate callback)
3157
{
3258
bool success = false;

PushSharp.Google.Chrome/ChromePushChannelSettings.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,34 @@ namespace PushSharp.Google.Chrome
88
public class ChromePushChannelSettings : IPushChannelSettings
99
{
1010
private const string CHROME_SEND_URL = "https://www.googleapis.com/gcm_for_chrome/v1/messages";
11+
private const string CHROME_AUTH_URL = "https://accounts.google.com/o/auth2/auth";
1112

1213
public ChromePushChannelSettings(string clientId, string clientSecret)
1314
{
1415
this.ClientId = clientId;
1516
this.ClientSecret = clientSecret;
1617

1718
this.Url = CHROME_SEND_URL;
19+
this.AuthUrl = CHROME_AUTH_URL;
1820
}
1921

2022
public string ClientId { get; private set; }
2123
public string ClientSecret { get; private set; }
2224

23-
internal string RefreshToken { get; set; }
24-
internal string GrantType { get; set; }
25+
public string RefreshToken { get; set; }
26+
public string GrantType { get; set; }
2527

2628
public string Url { get; private set; }
29+
public string AuthUrl { get; private set; }
2730

2831
public void OverrideUrl(string url)
2932
{
3033
Url = url;
3134
}
35+
36+
public void OverrideAuthUrl(string url)
37+
{
38+
AuthUrl = url;
39+
}
3240
}
3341
}

PushSharp.Google.Chrome/PushSharp.Google.Chrome.csproj

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<OutputType>Library</OutputType>
1010
<RootNamespace>PushSharp.Google.Chrome</RootNamespace>
1111
<AssemblyName>PushSharp.Google.Chrome</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1213
</PropertyGroup>
1314
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1415
<DebugSymbols>true</DebugSymbols>
@@ -31,25 +32,8 @@
3132
<Reference Include="System.Runtime">
3233
<HintPath>..\packages\Microsoft.Bcl.1.0.19\lib\net40\System.Runtime.dll</HintPath>
3334
</Reference>
34-
<Reference Include="System.Threading.Tasks">
35-
<HintPath>..\packages\Microsoft.Bcl.1.0.19\lib\net40\System.Threading.Tasks.dll</HintPath>
36-
</Reference>
37-
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop">
38-
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
39-
</Reference>
40-
<Reference Include="Microsoft.Threading.Tasks.Extensions">
41-
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.dll</HintPath>
42-
</Reference>
43-
<Reference Include="Microsoft.Threading.Tasks">
44-
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
45-
</Reference>
4635
<Reference Include="System.Net" />
47-
<Reference Include="System.Net.Http.WebRequest">
48-
<HintPath>..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.WebRequest.dll</HintPath>
49-
</Reference>
50-
<Reference Include="System.Net.Http">
51-
<HintPath>..\packages\Microsoft.Net.Http.2.0.20710.0\lib\net40\System.Net.Http.dll</HintPath>
52-
</Reference>
36+
<Reference Include="System.Net.Http" />
5337
</ItemGroup>
5438
<ItemGroup>
5539
<Compile Include="Properties\AssemblyInfo.cs" />

Tests/PushSharp.Tests/CoreTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void Setup()
2727
public void TestAppleRegistration()
2828
{
2929
broker.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, "pushsharp"));
30-
Assert.IsNotEmpty(broker.GetRegistrations<AppleNotification>());
30+
Assert.IsNotEmpty(broker.GetRegistrations<AppleNotification>().ToString());
3131
}
3232
}
3333
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using NUnit.Framework;
4+
5+
namespace PushSharp.Tests
6+
{
7+
public class GcmChromeTests
8+
{
9+
const string oauthClientId = "785671162406-hdjh5dfe38bp2b6c2quvh2oelq0ie48i.apps.googleusercontent.com";
10+
const string oauthSecret = "GgYTVbDxX4JogGSeh9IxS83f";
11+
const string redirectUrl = "https://developers.google.com/oauthplayground";
12+
13+
public GcmChromeTests ()
14+
{
15+
}
16+
17+
[Test]
18+
public void TestOAuth()
19+
{
20+
Google.Chrome.ChromePushChannel chan = new PushSharp.Google.Chrome.ChromePushChannel (new PushSharp.Google.Chrome.ChromePushChannelSettings(oauthClientId, oauthSecret)
21+
{
22+
GrantType = "4/m11YZRjo5yoYyuy3Wx8bIY1NtN3I.kvLUtsadF1YSuJJVnL49Cc_yg3RGfQI", RefreshToken = "1/737Kzd3sjIr8ME97HYam3fPW8euce6lHeP800RUXl8Y"
23+
});
24+
chan.RefreshAccessToken ();
25+
}
26+
}
27+
}
28+

Tests/PushSharp.Tests/PushSharp.Tests.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>PushSharp.Tests</RootNamespace>
1111
<AssemblyName>PushSharp.Tests</AssemblyName>
12-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1312
<FileAlignment>512</FileAlignment>
1413
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
1514
<RestorePackages>true</RestorePackages>
1615
<ProductVersion>12.0.0</ProductVersion>
1716
<SchemaVersion>2.0</SchemaVersion>
17+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1818
</PropertyGroup>
1919
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2020
<DebugSymbols>true</DebugSymbols>
@@ -26,7 +26,6 @@
2626
<WarningLevel>4</WarningLevel>
2727
</PropertyGroup>
2828
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29-
<DebugType>pdbonly</DebugType>
3029
<Optimize>true</Optimize>
3130
<OutputPath>bin\Release\</OutputPath>
3231
<DefineConstants>TRACE</DefineConstants>
@@ -48,8 +47,8 @@
4847
<Reference Include="Newtonsoft.Json">
4948
<HintPath>..\..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
5049
</Reference>
51-
<Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
52-
<HintPath>..\..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
50+
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
51+
<Private>False</Private>
5352
</Reference>
5453
</ItemGroup>
5554
<ItemGroup>
@@ -60,6 +59,7 @@
6059
<Compile Include="PushServiceTests.cs" />
6160
<Compile Include="TestServers\GcmTestServer.cs" />
6261
<Compile Include="TestServers\ApnsTestServer.cs" />
62+
<Compile Include="GcmChromeTests.cs" />
6363
</ItemGroup>
6464
<ItemGroup>
6565
<None Include="packages.config" />
@@ -85,6 +85,10 @@
8585
<Project>{0EC3A31E-B869-4465-ABDC-90C2E3CCC17D}</Project>
8686
<Name>PushSharp.Windows</Name>
8787
</ProjectReference>
88+
<ProjectReference Include="..\..\PushSharp.Google.Chrome\PushSharp.Google.Chrome.csproj">
89+
<Project>{84961658-42B9-4943-B738-ABED75EDE303}</Project>
90+
<Name>PushSharp.Google.Chrome</Name>
91+
</ProjectReference>
8892
</ItemGroup>
8993
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
9094
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />

Tests/PushSharp.Tests/packages.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3+
<package id="Microsoft.Bcl" version="1.0.19" targetFramework="net45" />
4+
<package id="Microsoft.Bcl.Async" version="1.0.16" targetFramework="net45" />
5+
<package id="Microsoft.Bcl.Build" version="1.0.5" targetFramework="net45" />
36
<package id="Moq" version="4.0.10827" targetFramework="net45" />
47
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
58
<package id="NUnit" version="2.6.2" targetFramework="net45" />

0 commit comments

Comments
 (0)